iPhone:使用简单的键/值字符串创建二进制 Plist 的最快方法
在 iPhone 上使用基于简单字符串的键/值对创建二进制 plist 的最佳方法是什么?我需要创建一个包含食谱和成分列表的 plist。然后我希望能够将其读入 NSDictionary,这样我就可以执行类似
NSString *ingredients = [recipes objectForKey:@"apple pie"];
通过 HTTP 请求读取 XML 数据文件并希望将所有键值对解析到 plist 中的操作。 XML 可能看起来像:
<recipes>
<recipe>
<name>apple pie</name>
<ingredients>apples and pie</ingredients>
</recipe>
<recipe>
<name>cereal</name>
<ingredients>milk and some other ingredients</ingredients>
</recipe>
</recipes>
理想情况下,我能够在运行时将其写入 plist,然后能够在运行时读取它并将其转换为 NSDictionary。
What's the best way to create a binary plist on the iPhone with simple string based key/value pairs? I need to create a plist with a list of recipe and ingredients. I then want to be able to read this into an NSDictionary so I can do something like
NSString *ingredients = [recipes objectForKey:@"apple pie"];
I'm reading in an XML data file through an HTTP request and want to parse all of the key value pairs into the plist. The XML might look something like:
<recipes>
<recipe>
<name>apple pie</name>
<ingredients>apples and pie</ingredients>
</recipe>
<recipe>
<name>cereal</name>
<ingredients>milk and some other ingredients</ingredients>
</recipe>
</recipes>
Ideally, I'll be able to write this to a plist at runtime, and then be able to read it and turn it into an NSDictionary later at runtime as well.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 Objective-C 中创建属性列表
这包含使用 CoreFoundation 或 Cocoa 创建属性列表文件的信息。
Creating a Property List in Objective-C
This contains information for creating a property list file using either CoreFoundation or Cocoa.
对于您的具体情况,请查看 NSDictionary 的接口并使用:
如果您只需要一本相当小的字典,您也可以尝试 NSUserDefaults。
For your specific case, look at the interface for NSDictionary and use:
If you only need one fairly small dictionary, you could also try NSUserDefaults.