iOS对plist文件进行读写
来源:互联网 发布:法军 知乎 编辑:程序博客网 时间:2024/06/06 07:53
把主要的代码先复制过来……
读Plist文件
NSString *errorDesc = nil; NSPropertyListFormat format; NSString *rootPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]; NSString *plistPath = [rootPath stringByAppendingPathComponent:@"bookmarks.plist"]; if (![[NSFileManager defaultManager] fileExistsAtPath:plistPath]) { plistPath = [[NSBundle mainBundle] pathForResource:@"bookmarks" ofType:@"plist"]; } NSData *plistXML = [[NSFileManager defaultManager] contentsAtPath:plistPath]; context.bookmarksDic = (NSMutableDictionary *)[[NSPropertyListSerialization propertyListFromData:plistXML mutabilityOption:NSPropertyListMutableContainersAndLeaves format:&format errorDescription:&errorDesc] retain]; keysArr = [[[context.bookmarksDic allKeys] sortedArrayUsingSelector:@selector(compare:)] retain]; if (!context.bookmarksDic) { NSLog(@"Error reading plist: %@, format: %d", errorDesc, format); }
写入Plist
Context *context = [Context getInstance]; NSString *rootPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]; NSString *plistPath = [rootPath stringByAppendingPathComponent:@"bookmarks.plist"]; NSString *error; NSData *plistData = [NSPropertyListSerialization dataFromPropertyList:context.bookmarksDic format:NSPropertyListXMLFormat_v1_0 errorDescription:&error]; if(plistData) { [plistData writeToFile:plistPath atomically:YES]; } else { NSLog(@"%@",error); [error release]; }
- iOS对plist文件进行读写
- iOS--对plist文件进行读写,增删改查
- IOS 对plist文件的读写
- IOS 对plist文件的读写
- iOS使用读写plist文件方式对数据进行增删改查
- IOS 读写plist文件
- ios plist文件读写
- ios plist 文件读写/plist 标签
- ios-plist文件读写操作
- ios plist文件的读写
- iOS-plist文件的读写
- iOS plist文件的读写
- ios-plist文件读写操作
- IOS Plist文件的读写
- iOS plist 文件读写操作
- iOS plist 文件的读写
- iOS应用剖析 ---- 对plist文件进行处理
- 对plist文件的读写操作
- Myeclipse10 下SVN安装方法
- Android Activity和Intent机制学习笔记
- 3种方法快速制作tpk文件
- Android中EditText的inputType属性值
- awk使用总结
- iOS对plist文件进行读写
- The protocols - Python
- XAML中Name与x:Name的区别
- 用linux来控制log文件的大小和数量
- FTP命令详解
- 长度为0的数组 —— C语言的非标准用法
- 1讲 html介绍 html运行原理①
- CSDN博客插入代码测试
- WIFEXITED/WEXITSTATUS/WIFSIGNALED