欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

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"]);
相关标签: ios