plist文件创建,储存,转化
来源:互联网 发布:做菜软件哪个好 编辑:程序博客网 时间:2024/04/29 04:08
创建.plist文件并存储
NSString *errorDesc; //用来存放错误信息
NSMutableDictionary *rootObj = [NSMutableDictionary dictionaryWithCapacity:4]; //NSDictionary, NSData等文件可以直接转化为plist文件NSDictionary *innerDict;NSString *name;
Player *player;
NSInteger saveIndex;
for(int i = 0; i < [playerArray count]; i++) {
player = nil;
player = [playerArray objectAtIndex:i];
if(player == nil)
break;
name = player.playerName;// This "Player1" denotes the player name could also be the computer name
innerDict = [self getAllNodeInfoToDictionary:player];
[rootObj setObject:innerDict forKey:name]; // This "Player1" denotes the person who start this game
}
player = nil;NSData *plistData = [NSPropertyListSerialization dataFromPropertyList:(id)rootObj format:NSPropertyListXMLFormat_v1_0 errorDescription:&errorDesc];红色部分可以忽略,只是给rootObj添加一点内容。这个plistData为创建好的plist文件,用其writeToFile方法就可以写成文件。下面是代码:
/*得到移动设备上的文件存放位置*/
NSString *documentsPath = [self getDocumentsDirectory];
NSString *savePath = [documentsPath stringByAppendingPathComponent:@"save.plist"];
/*存文件*/
if (plistData) {
[plistData writeToFile:savePath atomically:YES];
}
else {
NSLog(errorDesc);
[errorDesc release];
}- (NSString *)getDocumentsDirectory {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
return [paths objectAtIndex:0];
}
读取plist文件并转化为NSDictionary
NSString *documentsPath = [self getDocumentsDirectory];
NSString *fullPath = [documentsPath stringByAppendingPathComponent:@"save.plist"];NSMutableDictionary* plistDict = [[NSMutableDictionary alloc] initWithContentsOfFile:fullPath];
- plist文件创建,储存,转化
- 数据储存之plist文件
- 创建plist文件
- 代码创建plist文件
- 本地 json文件转化成plist文件
- 将数据(数组)储存到.plist文件中
- 转化txt文本为plist文件
- 创建与读取 plist 文件
- iOS Plist文件的创建
- iOS-生成plist文件,在项目中代码创建plist
- plist文件的创建与读取
- iOS 创建.写入.读取plist文件
- 使用Xcode创建plist文件和使用
- iOS plist文件创建和读写
- iOS plist文件创建于读取
- iOS 创建.写入.读取plist文件
- 本地plist文件创建、写入、读取
- OC 创建和写入plist文件
- 关于strust2 使用freemarker 指定模板路径前缀的纠结
- Ubuntu12.04上编译hadoop-eclipse-plugin-1.0.4.jar包
- 关于web app,选择 PhoneGap、Sencha Touch 或者 jQuery Mobile 哪个比较好
- MFC warning LNK4070处理
- VS2010使用C++/CLI编程窗口无法显示问题解决方法
- plist文件创建,储存,转化
- 工厂模式
- cglib 动态生产类原理
- 推广经验分享
- HEVC学习(二十六) —— 量化之一
- css笔记小结
- 跨部门工作安排与绩效考评解决方案
- ubuntu12.04 修改mysql默认编码方式
- 计划任务工具 cron crontab的配置和说明