Michael
Michael

Reputation: 277

Storing Default and Single Values in Objective-C using <CoreData/CoreData.h>

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.

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.

Upvotes: 0

Views: 275

Answers (2)

Mundi
Mundi

Reputation: 80273

I do not think that using Core Data to store user preferences is a good idea.

Reduce and simplify your code by employing NSUserDefaults.

[[NSUserDefaults standardUserDefaults] setBool:NO forKey:kStringMacro];
trueOrFalse = [[NSUserDefaults standardUserDefaults] boolForKey:kStringMacro];

Upvotes: 1

DogCoffee
DogCoffee

Reputation: 19966

This is how you set a default value in the core data model.

enter image description here

Upvotes: 0

Related Questions