获取plist的内容
我怎样才能获取这个plist的内容?
我对不同的元素以及如何访问它们有点困惑。
如何访问这些词典以及词典中的词典?
如果我想先复制这些数据,而不是总是从 plist 中读取,它会大大提高性能吗?
如何通过遍历结构级别将所有这些数据放入我的应用程序中?
谢谢
How can I get the content of this plist?
I am a little confused on the different elements and how to access them.
How does one access these dictionaries, and dictionaries in dictionaries?
What if I want to copy this data first, would it increase performance by a lot, rather than always reading from the plist?
How can I get all of this data into my app, by going through the structure levels?
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
读取属性列表的最简单方法是使用
NSDictionary
上的便捷方法(如果根元素是数组,则使用NSArray
),如下所示:从那时起,plist 文件就只是一个普通的字典。使用
objectForKey:
等获取值。为了更快地访问深层子节点,您可以使用valueForKeyPath:
,如下所示:对于 plist 文件上更复杂的操作,您应该使用
NSPropertyListSerialization
,它具有多个类方法以获取更多信息对读取和写入属性列表文件的细粒度访问。The easiest way to read a property list is by using a convenience method on
NSDictionary
(OrNSArray
if your root element is an array) like so:From there on the plist file is just a normal dictionary. Use
objectForKey:
, etc to get to the values. For faster access to deep child nodes you can usevalueForKeyPath:
like this for example:For more complex operations on plist files you should use
NSPropertyListSerialization
that have several class methods for more more fine grained access to reading and writing property list files.您应该查看 NSPropertyListSerialization class,这使得解析 plist 相对简单。
这是一些示例代码: http://iphoneincubator.com/blog/tag/nspropertylistserialization
You should check out the NSPropertyListSerialization class, which makes parsing plists relatively straightforward.
Here's a bit of sample code: http://iphoneincubator.com/blog/tag/nspropertylistserialization
SWIFT代码
Swift Code