##讀取ui
//獲取已有完整路徑 NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"MyPropertyList" ofType:@"plist"]; NSMutableDictionary *usersDic = [[NSMutableDictionary alloc]initWithContentsOfFile:plistPath]; NSString *name = [usersDic valueForKey:@"Name"]; NSString *phone = [usersDic valueForKey:@"Phone"]; NSLog(@"讀取手動建立的plist文件的屬性的值 ====%@======%@",name,phone);//讀取手動建立的plist文件的屬性的值 ====鄒傑======18971118756
1.plist文件必須添加到工程的Build phases -> compile Sources裏 2.plist文件必須(copy if need)真實存在於路徑中atom
##建立&&寫入數據code
//獲取本地沙盒路徑 NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);//文檔路徑 //獲取完整路徑 NSString *documentsPath = [path objectAtIndex:0]; NSString *plistPath = [documentsPath stringByAppendingPathComponent:@"MY_PropertyList.plist"]; NSMutableDictionary *usersDic = [[NSMutableDictionary alloc ] init]; //設置屬性值 [usersDic setObject:@"孫悟空" forKey:@"name"]; [usersDic setObject:@"sunwukong" forKey:@"password"]; //寫入文件 [usersDic writeToFile:plistPath atomically:YES]; //設置屬性值 [usersDic setObject:@"鄒傑" forKey:@"name"]; [usersDic setObject:@"zoujie" forKey:@"password"]; //寫入文件 [usersDic writeToFile:plistPath atomically:YES];