如何在 iOS 中存储应用程序设置,例如 INI / CONF?
我从 iOS 编程开始。我有一个问题希望你能帮忙。
我有一个测试应用程序作为从 URL 读取的 RSS 阅读器。例如:abc.com/feed
我想将一些数据存储在设置文件中,例如 Windows 上的 INI 或 Linux 上的 CONF,例如:
URL = abc.com/feed
NumberOfItem = 10
Interval = 3 # minus
iOS 应用程序使用哪种文件来存储其设置?是否有任何方法/类/API/...支持读/写?
PS 我在 Appcelerator 上使用Titanium。
非常感谢!
I am starting with iOS programming. I have a question hope you can help.
I have a test app as an rss reader that reads from a URL. For example: abc.com/feed
I want to store some data in a setting file like INI on Windows or CONF on Linux, example:
URL = abc.com/feed
NumberOfItem = 10
Interval = 3 # minus
What kind of file does an iOS app use to store it's settings? Is there any method/class/API/... which supports read/write on it?
P.S. I am using Titanium at Appcelerator.
Thanks so much!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
使用属性。
http://developer.appcelerator.com/apidoc/mobile/latest /Titanium.App.Properties-module
Use Properties.
http://developer.appcelerator.com/apidoc/mobile/latest/Titanium.App.Properties-module
您可以将数据保存在
NSUserDefaults
中,完整的Apple 的 API 文档至在
NSUserDefaults
中保存某种数据只需调用[[NSUsererDefaults standardUserDefaults] setObject:myObject forKey:@"myObjectKey"]
。要读取数据,请调用
[[NSUserDefaults standardUserDefaults] objectForKey:@"myObjectKey"]
You can save data in the
NSUserDefaults
the complete API-Documentation from AppleTo save some kind of data in the
NSUserDefaults
simply call[[NSUsererDefaults standardUserDefaults] setObject:myObject forKey:@"myObjectKey"]
.To read the data call
[[NSUserDefaults standardUserDefaults] objectForKey:@"myObjectKey"]
我使用属性列表 (.plist),本质上是一个 xml 文件,可以由 NSDictionary(及其所有变体)读取和写入。对于简单的设置,正如 @Tobi 建议的那样,NSUserDefaults。对于更大、更复杂的数据集,我使用 .plists。对于需要保留的每个类,我创建一个 +(id) loadFromDictionary 和 -(NSDictionary*) asDictionary 方法。
I use property lists (.plist), essentially an xml file, that can be read and written by the NSDictionary (and all its variants). For simple settings , as @Tobi suggests, NSUserDefaults. For larger, more complex datasets, i go with .plists. For each class that needs to persist, i create a +(id) loadFromDictionary and -(NSDictionary*) asDictionary method.
如果您只想存储简单数据,可以使用
NSUserDefaults
NSUserDefaults 示例
If you just want to store simple data you can use
NSUserDefaults
NSUserDefaults Example