1

What is the standard way to preload an app with core data on delivert, for example i want to deliver my app with an example document which is to be available through core data after install.

So how do i package some initial data with an Core Data iOS App?

David Karlsson
  • 9,396
  • 9
  • 58
  • 103
  • 1
    possible duplicate of [Prefill information in Core Data at startup](http://stackoverflow.com/questions/5544890/prefill-information-in-core-data-at-startup) – Martin R Nov 23 '13 at 15:47
  • See also: [Any way to pre populate core data?](http://stackoverflow.com/questions/2230354/any-way-to-pre-populate-core-data). – Martin R Nov 23 '13 at 15:48

1 Answers1

0

You can detect the first launch and then add the Data:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    if ([[NSUserDefaults standardUserDefaults] boolForKey:@"HasLaunchedOnce"])
    {

    }
    else
    {
      NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
        [prefs setBool:YES forKey:@"HasLaunchedOnce"];

        [[NSUserDefaults standardUserDefaults] synchronize];
        //Add your data here in the Core Data Database.
    }

    return YES;
}
iCode
  • 1,456
  • 1
  • 15
  • 26