#pragma mark - 创建一个plist文件
NSString *filename=[PATH stringByAppendingPathComponent:@"test.plist"];
NSFileManager* fileManager = [NSFileManager defaultManager];
[fileManager createFileAtPath:filename contents:nil attributes:nil];
#pragma mark - 写入文件
//一般来讲plist文件最上层节点,即根节点,root节点是一个字典
NSArray * array1 = @[@"One", @"Two", @4];
NSArray * array2 = @[[NSDate date], @"Four"];
NSArray * array3 = @[@4.5, @"Five"];
NSDictionary * dict = @{@"数组1": array1, @"数组2":array2, @"数组3":array3};
//写出plist文件,如果有不符合要求的对象,则创建plist文件会失败
//数组,字典,字符串,NSData都有这个方法,其中数组和字典会写出plist文件,是以xml格式存储基本数据
[dict writeToFile:filename atomically:NO];
#pragma mark - 读取文件
//读取plist文件首先要知道plist文件里的内容
NSDictionary * dict2 = [[NSDictionary alloc] initWithContentsOfFile:filename];
NSLog(@"%@", dict2);
[dict2 release];
网友评论