通过代码创建plist文件 [英] Create plist file via code
本文介绍了通过代码创建plist文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想创建一个这样的plist文件:
I want to create a plist file like this:
,然后将其放置在Caches文件夹中. 我已经知道如何获取数据.
in code, and then it will be in the Caches folder. I already know how to fetch the data.
推荐答案
您可以这样做:
//Create a Mutant Dictionary
NSMutableDictionary *theMutantDict = [[NSMutableDictionary alloc] init];
//Fill it with data
[theMutantDict setObject:@"John" forKey:@"Name"];
[theMutantDict setObject:@"Doe" forKey:@"Lastname"];
//Then search for cache dir
NSString *libraryDir = [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory,
NSUserDomainMask, YES) objectAtIndex:0];
NSString *cacheDir = [libraryDir stringByAppendingPathComponent:@"Caches"];
//Then write the file
NSString *filePath = [cacheDir stringByAppendingString:@"/TheFile.plist"];
[theMutantDict writeToFile:filePath atomically:YES];
这篇关于通过代码创建plist文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文