`
heji
  • 浏览: 87746 次
  • 性别: Icon_minigender_1
  • 来自: 重庆
社区版块
存档分类
最新评论

IOS中plist的读写操作

    博客分类:
  • ios
阅读更多
从项目中读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"]);
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics