【发布时间】:2011-01-12 04:39:26
【问题描述】:
我已阅读 Apple 的 plist 文档:http://developer.apple.com/library/mac/documentation/cocoa/Conceptual/PropertyLists/PropertyLists.pdf
但是我有几个问题:
1) 当我们使用 [dict writeToFile:plistPath atomically:YES] API 时,它会覆盖 plist 的当前内容吗?它没有在文档中说明任何内容。
2) 我们是否应该通过新文件->资源->属性列表在 Xcode 中手动创建 plist?或者我们应该有这个:
NSFileManager *fileManager = [NSFileManager defaultManager];
NSData *xmlData = [NSPropertyListSerialization //... a very long line here
if([fileManager fileExistsAtPath:plistPath]) {
[xmlData writeToFile:plistPath atomically:YES];
}
else {
[fileManager createFileAtPath:plistPath contents:xmlData attributes:nil];
}
3) 我们如何检查我们是否真的将数据写入属性列表?我试过 products -> myapp.app -> "reveal in finder" -> 右键单击 -> show package contents,那里有一些 plist,但是我看不到正在写入的数据!这是否意味着我无法将数据写入 plist?
编辑:谢谢大家!抱歉今天犯傻了!
【问题讨论】:
标签: iphone objective-c cocoa-touch ios4 plist