IOS中plist的读写操作
程序员文章站
2022-04-11 15:49:02
...
从项目中读plist文件
在沙盒目录里创建并且读写
NSString *path = [[NSBundle mainBundle] pathForResource:@"heji" ofType:@"plist"];
NSMutableDictionary *mutableDictionary = [[NSMutableDictionary alloc] initWithContentsOfFile:path];
NSLog(@"%@", [mutableDictionary objectForKey:@"he"]);
NSLog(@"%@", [[mutableDictionary objectForKey:@"nihao"] objectForKey:@"d_1"]);
NSLog(@"%@", [[mutableDictionary objectForKey:@"nihao"] objectForKey:@"d_2"]);
NSLog(@"%@", [[mutableDictionary objectForKey:@"nihao"] objectForKey:@"d_3"]);
NSLog(@"%@", [mutableDictionary objectForKey:@"ji"]);
在沙盒目录里创建并且读写
NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];
[dic setValue:@"gagagag" forKey:@"key"];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *myPath = [paths objectAtIndex:0];
NSString *realpath = [myPath stringByAppendingPathComponent:@"test.plist"];
[dic writeToFile:realpath atomically:YES];
NSMutableDictionary *mutableDictionary1 = [[NSMutableDictionary alloc] initWithContentsOfFile:realpath];
NSLog(@"%@", [mutableDictionary1 objectForKey:@"key"]);
上一篇: java抖音视频解析(去水印)
下一篇: mac下PHP安装扩展phpreids