开发者

How do I read a plist?

I have a plist that is bina开发者_如何学Cry plist.

Do i need to convert it before I can use it? or can my application read the plist?


Use +[NSDictionary dictionaryWithContentsOfURL:]. It can understand binary plists.

Edit:

As Peter Hosey points out, this will only work if the root element is a dictionary. If the root element is an array, you can use +[NSArray arrayWithContentsOfURL:].


A much more general solution is to use NSPropertyListSerialization, as suggested by Vladimir in his answer that he deleted. It both serializes (makes plist data from an object) and deserializes (re-creates an object tree from plist data).

It is always able to parse any valid plist, binary or otherwise, regardless of the type of the root element; you may then want to inspect the object it returns to make sure it's of a type you expect.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜