数组写入plist文件(文件储存到cache路径下)
NSArray *words = @[@"a", @"b", @"c", @"d", @"e", @"f", @"g", @"h", @"i", @"j", @"k", @"l", @"m", @"n", @"o", @"p", @"q", @"r", @"s", @"t", @"u", @"v", @"w", @"x", @"y", @"z"];
NSString *cachePatch = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)[0];
NSString *filePath = [cachePatch stringByAppendingPathComponent:@"words.plist"];
[words writeToFile:filePath atomically:YES];
字典写入plist文件
NSDictionary *personInfo = @{
@"name" : @"amber",
@"age" : @"18",
@"height" : @"165"};
NSString *cachePatch = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)[0];
NSString *filePath = [cachePatch stringByAppendingPathComponent:@"personInfo.plist"];
NSURL *fileUrl = [NSURL fileURLWithPath:filePath];
[personInfo writeToURL:fileUrl atomically:YES];
将字典数组写入plist文件
NSArray *products = @[
@{@"icon" : @"liantiaobao", @"title" : @"链条包"},
@{@"icon" : @"shoutibao", @"title" : @"手提包"},
@{@"icon" : @"danjianbao", @"title" : @"单肩包"},
@{@"icon" : @"shuangjianbao", @"title" : @"双肩包"},
@{@"icon" : @"xiekuabao", @"title" : @"斜挎包"},
@{@"icon" : @"qianbao", @"title" : @"钱包"}
];
NSString *cachePatch = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)[0];
NSString *filePath = [cachePatch stringByAppendingPathComponent:@"products.plist"];
NSURL *fileUrl = [NSURL fileURLWithPath:filePath];
[products writeToURL:fileUrl atomically:YES];