如何在 iOS 中存储应用程序设置,例如 INI / CONF?

发布于 2025-01-04 17:26:19 字数 358 浏览 7 评论 0原文

我从 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

野却迷人 2025-01-11 17:26:19

您可以将数据保存在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 Apple

To 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"]

梦中楼上月下 2025-01-11 17:26:19

我使用属性列表 (.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.

路弥 2025-01-11 17:26:19

如果您只想存储简单数据,可以使用 NSUserDefaults
NSUserDefaults 示例

If you just want to store simple data you can use NSUserDefaults
NSUserDefaults Example

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文