0

I have an iphone app with core data. I pre-populate an entity called DefaultValues before user download the app from app store, he then add his own data to other entities. DefaultValues never gets changed. Now, i want to modify some data from my DefaultValues entity and add some new data to it (no change in entity schema). How do i do it??

Off course, i did some research online before asking this question. I found some links here Link 1:

Link 2

but there is no concrete answer to this question.

Should i have to perform core data versioning and data migration?? Or how should i just change DefaultValues entity without erasing users data???

Thanks

Community
  • 1
  • 1

1 Answers1

0

As for the actual migration, search for "Lightweight migration". There are some Apple docs about it, also there's a topic here

However, you say you use Core Data to store Default Values. You probably should not use Core Data but instead NSUserDefaults.

Use this bit of code to set a default value for a setting:

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setBool:YES forKey:@"SomeSetting"];

you can later get the value for SomeSetting like so:

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
BOOL currentSetting = [defautls boolForKey:@"SomeSetting"];

Similarly, you can store strings, numbers and a bunch of other stuff.

Community
  • 1
  • 1
fabian789
  • 8,348
  • 4
  • 45
  • 91
  • Thanks fabian789. I use core data and my DefaultValues entity has at least 50 rows in it. Now, i want to insert one more row to it, don't want to modify data model. How do i do it without erasing users data present in other entities? How NSUserDefaults would help me. Can you please explain it in more details. Thanks. – apiphone2020 Mar 02 '11 at 17:19
  • I updated my question. Note that you can store **as many "rows"** as you want in `NSUserDefaults`. Obviously, my answer doesn't show how to "insert one more row", I just assumed that using `NSUserDefaults` would be better as you say your data stores "DefaultValues". – fabian789 Mar 03 '11 at 17:49