2

I develop iOS app, which is using Core Data and I would like to create same sample data records when the app is installed. Is there any easy way how to do it..?

For example there is entity "Employee" and I would like to add "John Doe" employee when the app is installed.

Can someone help me with that? Thanks

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Pavel Smejkal
  • 3,600
  • 6
  • 27
  • 45

2 Answers2

2

Is a pre-populated database for coredata what you want ? If so, I think you should find this link interesting : Any way to pre populate core data?

Otherwise, you can maybe save in user defaults a boolean to know if it is the first time that the application has been launched. If this is the first time, you write some code to add the objects you want.

Community
  • 1
  • 1
Sunder
  • 503
  • 1
  • 5
  • 17
1

Thanks Sunder for you answer.

In the end I decided for fast solution by checking whether the app is running first time in the AppDelegate didFinishLaunching method:

NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
if (![userDefaults valueForKey:@"PCAppDelegateFirstRun"] )
{
    [PCDatabase createSampleData];
    [userDefaults setBool:YES forKey:@"PCAppDelegateFirstRun"];
}
Pavel Smejkal
  • 3,600
  • 6
  • 27
  • 45