使用< CoreData / CoreData.h>在Objective-C中存储默认值和单值。 [英] Storing Default and Single Values in Objective-C using <CoreData/CoreData.h>
问题描述
我试图将默认值存储在数据模型
中调用 CoreData.xcdatamodeld
。该文件包括一个名为 Settings
的实体。在设置
中,有六个布尔
值。
I'm trying to store default values in a Data Model
called CoreData.xcdatamodeld
. The file includes a single entity called Settings
. Within Settings
, there are six Boolean
values.
当iOS应用程序第一次启动时,我要将 NO
的默认值设置为这六个布尔$ c>的默认值$ c>值。从那里,可以更改为默认值。我也只需要与每个
布尔$>相关联的单个值
YES
或 NO
实体中的设置
When the iOS application launches for the first time, I want the default values of NO
to be set as default values for these six Boolean
values. From there, changes can be made to the default value. I also only want a single value of YES
or NO
associated with each Boolean
value in the Settings
entity. After changes are made, and the application is cleared from memory, and restarted, the data model should include the latest values that have been defined by the user.
我如何去做这个?我已经有了处理这些价值观和改变的能力的结构,我只是想从理论的角度来看这个。
How would I go about doing this? I already have the structure in place to deal with those values and their ability to change, I was just wondering about this from a theoretical point of view.
推荐答案
我不认为使用Core Data存储用户偏好是一个好主意。
I do not think that using Core Data to store user preferences is a good idea.
使用 NSUserDefaults
减少和简化您的代码。
Reduce and simplify your code by employing NSUserDefaults
.
[[NSUserDefaults standardUserDefaults] setBool:NO forKey:kStringMacro];
trueOrFalse = [[NSUserDefaults standardUserDefaults] boolForKey:kStringMacro];
这篇关于使用< CoreData / CoreData.h>在Objective-C中存储默认值和单值。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!