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 8136837
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T10:53:04+00:00 2026-06-06T10:53:04+00:00

Previously, I have an app that uses core data. I use same store url

  • 0

Previously, I have an app that uses core data. I use same store url to init NSManagedObjectModel and create NSPersistentStoreCoordinator. However, in the new app, I tried to use the same way, the model can not be created. So I have to use a model url (I found it in this forum) to be able to create NSManagedObjectModel. What is the issue?

Here is from OLD app:

- (NSString *)storeName
{
    return @"ABC.storedata";
}

- (NSURL *)storeUrl
{
    NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:self.storeName];
    return storeURL;
}

- (NSManagedObjectModel *)managedObjectModel {
    if (_managedObjectModel == nil) {
        _managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:[self storeUrl]];
    }
    return _managedObjectModel;
}


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

       abort();
    }    

    return _persistentStoreCoordinator;
}

Here is from NEW app:

- (NSString *)storeName
{
    return @"DEF.sqlite";
}

- (NSURL *)storeUrl
{
    NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:self.storeName];
    return storeURL;
}

- (NSURL *)modelUrl
{
    NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"DEF" withExtension:@"momd"];
    return modelURL;
}

- (NSManagedObjectModel *)managedObjectModel {
    if (_managedObjectModel == nil) {
        _managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:[self modelUrl]];
    }
    return _managedObjectModel;
}


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

       abort();
    }    

    return _persistentStoreCoordinator;
}
  • 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-06T10:53:05+00:00Added an answer on June 6, 2026 at 10:53 am

    You can never use the same URL for both model and persistent store because they are two very different things.

    Model URL must point to the actual model resource included in your Xcode project which is a .momd file package. Persistent store is in your case a database, a .sqlite file in documents directory.

    I cannot imagine how it could have worked in the past. One possibility is that since your ABC.storedata did not have a trailing .sqlite, Core Data must have added a .sqlite to it behind the scenes and DEF.storedata could have matched your model name somehow?

    This is the proper way to initialize a model where you replace “Model” with the name you have in the Xcode project for model resource:

    NSURL *modelURL             = [[NSBundle mainBundle] URLForResource:@"Model" withExtension:@"momd"];        
    model                       = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL];
    

    As for persistent store, there are no restrictions. In most cases it should be in application documents directory though.

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

Sidebar

Related Questions

I have an app in the app store that uses Core Data to persist
I have an app that fetches data from the internet and uses CoreData to
I have previously been told that I should always use Randomize() before I use
In my app I am using core data and uses version 1 to 5.
I have a winforms app that uses a strongly typed custom DataSet for holding
we have an APP, that uses many local resources, such as windows printing API,
In my app I have a UIView derived class Canvas that uses touchesBegan: withEvent:
I have a plugin for an RCP app that uses BIRT. I have a
We currently have a live app that features episodic content in the App store.
I have a working Facebook app that most users will use just once. Leading

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.