使用< CoreData / CoreData.h>在Objective-C中存储默认值和单值。 [英] Storing Default and Single Values in Objective-C using <CoreData/CoreData.h>

查看:262
本文介绍了使用< CoreData / CoreData.h>在Objective-C中存储默认值和单值。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将默认值存储在数据模型中调用 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>值。从那里,可以更改为默认值。我也只需要与每个布尔相关联的单个值 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆