iphone - .plist 文件如何在 iOS 中工作

标签 iphone ios plist

我是 iOS 开发的新手,我想知道 .plist 文件在 iOS 中是如何工作的。任何人都可以通过举例说明如何在 .plist 中读取和写入数据来帮助我吗?

最佳答案

是的:

NSString *rootPath = [[NSBundle mainBundle] bundlePath];
NSString *pListPath = [rootPath stringByAppendingPathComponent:@"Settings.bundle/Root.plist"];
NSDictionary *pList = [NSDictionary dictionaryWithContentsOfFile:pListPath];

写入文件也不是太难:

NSDictionary *dict;
NSData *data = [NSPropertyListSerialization dataWithPropertyList:dict format:NSPropertyListXMLFormat_v1_0 options:0 error:&error];
[data writeToFile:self.saveToPath atomically:YES];

关于iphone - .plist 文件如何在 iOS 中工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9634390/

相关文章:

iphone - 可变集合作为属性的最佳实践

iphone - 类似 CG/NSPoint 的整数元组类型?

iOS:在特定坐标处,添加一个 UIView 作为另一个 UIView 的 subview

ios - 快速通过 UITextField 的 UILongPressGestureRecognizer

IOS 内存管理 - 将视频写入临时文件

iOS 位置管理器比每秒更新一次更频繁

ios - 将 "Delete"按钮添加到 UITableViewCell

ios - 将 nil 传递给 archivedDataWithRootObject 返回奇怪的 NSData

ios - 显示 pList 中特定的 "categories"

ios - Swift:遍历 plist