Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8508365
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T03:08:32+00:00 2026-06-11T03:08:32+00:00

To pre-populate CoreData in my app upon first launch, I have included a PreModel.sqlite

  • 0

To pre-populate CoreData in my app upon first launch, I have included a PreModel.sqlite file that was previously created by the app from data that it downloaded from a web service, which includes images.

To populate the model, I do this:

- (NSPersistentStoreCoordinator *)persistentStoreCoordinator
{    
    if (_persistentStoreCoordinator != nil) {
        return _persistentStoreCoordinator;
    }

    NSLog(@"creating new store");

    NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"PreModel.sqlite"];

    if(![[NSFileManager defaultManager] fileExistsAtPath:[storeURL path]]) {

        NSString *sqlitePath = [[NSBundle mainBundle] pathForResource:@"PreModel" ofType:@"sqlite"];
        if (sqlitePath) {
            NSError *error = nil;
            [[NSFileManager defaultManager] copyItemAtPath:sqlitePath toPath:[storeURL path] error:&error];
            if (error) {
                NSLog(@"Error copying sqlite database: %@", [error localizedDescription]);
            }
        }
    }     

    NSError *error = nil;
    _persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
    if (![_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:nil error:&error]) {

        NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
        abort();
    }   

    return _persistentStoreCoordinator;
}

It seems to work. But I have 2 questions:

  1. If the sqlite file is just a database file and does not actually contain any images, how is the app finding and loading the images on first launch?
  2. Even on subsequent runs of the app I see “creating new store” logged every time. Why is _persistentStoreCoordinator always nil? I am clearly setting it in the code.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T03:08:33+00:00Added an answer on June 11, 2026 at 3:08 am
    1. It’s possible to store images in a database file, usually as binary blobs (which look like instances of NSData in Core Data). If you can provide more info about your model or the code that stores/loads the images, we can be more specific.
    2. “Creating new store” is expected to get logged every time the app is launched in this instance. Even though the SQLite file is persistent on disk, you can’t expect data structures in your code to stick around when your app is terminated – you need to create a new persistent store object for your program every time it launches.

      Think of it like assigning NSInteger x = 10, then expecting to be able to quit and relaunch your program while maintaining that x has the value 10. That’s not how programs work – you’d need to reassign x = 10 before you can expect to read x and get 10 back. The variable _persistentStoreCoordinator works the same way here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a well pre-populated sqlite file that i copied into my project (in
I have a form that I pre-populate with test data though jQuery. $('INPUT[name=subscription.FirstName]').val('Jef'); but
I created a pre-populate SQL Lite DB an added it to my app as
If you want to pre-populate a database (SQLite) in Android, this is not that
I have a UITextView that has a fixed width and height. I pre-populate the
I have a text area that I want to pre-populate with some specific text
I have a situation where I want to pre populate a CoreData DB with
I'm importing pre-created Crystal Reports into a report project, and I want to populate
I have a Core Data-based iPhone app with a pre-populated read-only database. What protection
I have to pre-populate two calendars with values. I need it to be in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.