plist文件代码展示

#pragma mark - bundle下——即工程内plist文件内容的获取及修改

#pragma mark 读取

NSString * bundlePath = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"plist"];

NSMutableDictionary * data1 = [[NSMutableDictionary alloc] initWithContentsOfFile:bundlePath];

NSLog(@"%@", data1);

#pragma mark 添加

[data1 setObject:@"内容" forKey:@"关键字"];

[data1 setObject:@"hahaa" forKey:@"ccc"];

[data1 setObject:@"afee" forKey:@"aaaaa"];



#pragma mark - 操作沙盒内的plist文件

//获取沙盒下的Documents目录

NSArray * pathsArray=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);

NSString * plistPath = [pathsArray objectAtIndex:0];

//得到完整的文件名

NSString * filename=[plistPath stringByAppendingPathComponent:@"test.plist"];

//内容写入

[data1 writeToFile:filename atomically:YES];

//读取

NSMutableDictionary * data = [[NSMutableDictionary alloc] initWithContentsOfFile:filename];

NSLog(@"data1:%@", data);




本文档用于代码内容展示

你可能感兴趣的:(plist文件代码展示)