gpt4 book ai didi

ios - NSUserDefaults 还是后端?

转载 作者:行者123 更新时间:2023-11-28 19:55:02 25 4
gpt4 key购买 nike

我必须在非常紧迫的期限内发布一个简单的应用程序,所以我没有时间学习我所知道的东西(例如学习核心数据)。使用 NSUserDefaults 为我的应用存储数据是否合适?它几乎就像一个 list 应用程序,用户可以在其中列出项目,每个项目都附带一些数据。

除此之外,我会使用像 Parse 这样的服务,由于使用它构建了我的最后一个应用程序,我可以处理它。

如果您将 NSUserDefaults 用于设置/首选项之外的其他内容,Apple 会拒绝应用吗?

谢谢!

最佳答案

来自 Apple's documentation :

The NSUserDefaults class provides a programmatic interface for interacting with the defaults system. The defaults system allows an application to customize its behavior to match a user’s preferences. For example, you can allow users to determine what units of measurement your application displays or how often documents are automatically saved. Applications record such preferences by assigning values to a set of parameters in a user’s defaults database. The parameters are referred to as defaults since they’re commonly used to determine an application’s default state at startup or the way it acts by default.

[...]

Values returned from NSUserDefaults are immutable, even if you set a mutable object as the value. For example, if you set a mutable string as the value for "MyStringDefault", the string you later retrieve using stringForKey: will be immutable.

换句话说,这不是存储可变应用程序数据的地方。

如果最终用户要修改 list 数据(即添加新项目或编辑 list 上的项目文本),那么学习如何使用 Core Data 确实是值得的。多年来,它真的变得非常容易学习和使用。

您可以在 http://code.tutsplus.com/series/core-data-from-scratch--cms-653 找到一系列很棒的 Core Data 教程

如果您正在寻找针对 iOS 8 和 Swift 的更新内容(尽管它们主要是针对新语言的语法更改),您可以查看 http://www.raywenderlich.com/85578/first-core-data-app-using-swift .

关于ios - NSUserDefaults 还是后端?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26986140/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com