iphone:plist的读写存!

- (void)viewDidLoad {

//读取plist
NSString *path = [[NSBundle mainBundle] pathForResource:@”demo” ofType:@”plist”];
NSMutableDictionary *data = [[NSMutableDictionary alloc] initWithContentsOfFile:path];
NSLog(@”%d”,[data count]);

//添加一项内容
[data setObject:@"content" forKey:@"item4"];

//获取应用程序沙盒的Documents目录
NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
path = [paths objectAtIndex:0];

//得到完整的文件名
NSString *filename=[path stringByAppendingPathComponent:@"test.plist"];

[data writeToFile:filename atomically:YES];
[data release];
[super viewDidLoad];
}


你可能感兴趣的:(iphone:plist的读写存!)