plist文件的相关操作

// 加载plist文件
NSString *path = [[NSBundle mainBundle]pathForResource:@Property List ofType:@plist];
NSMutableDictionary *data = [[NSMutableDictionary alloc]initWithContentsOfFile: path];

//获取应用沙盒的Douch
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentationDirectory, NSUserDomainMask, YES);
NSString *plist1 = [paths objectAtIndex:0];

//获取一个plist文件
NSString *filename = [plist1 stringByAppendingString:@test.plist];
[data writeToFile:filename atomically:YES];
NSMutableDictionary *data1 = [[NSMutableDictionary alloc]initWithContentsOfFile:filename];
//打印出字典里的数据
NSLog(@%@,data1);

//修改一个plist文件的数据
[data1 setObject:@要修改的数值 forKey:@要修改的name];
[data1 writeToFile:filename atomically:YES];

你可能感兴趣的:(plist文件的相关操作)