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

  • Home
  • SEARCH
  • 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 4123136
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T23:34:21+00:00 2026-05-20T23:34:21+00:00

I have a Mac App already created and distributed on the App Store to

  • 0

I have a Mac App already created and distributed on the App Store to many customers, and I need to add an attribute to the Core Data Model. I read the documentation provided by Apple, available here.

However, it gives this block of code to enable automatic migration:

NSError *error;
NSPersistentStoreCoordinator *psc = <#The coordinator#>;
NSURL *storeURL = <#The URL of a persistent store#>;
NSDictionary *optionsDictionary =
    [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:YES]
                    forKey:NSMigratePersistentStoresAutomaticallyOption];

NSPersistentStore *store = [psc addPersistentStoreWithType:<#Store type#>
                                configuration:<#Configuration or nil#>
                                URL:storeURL
                                options:optionsDictionary
                                error:&error];

.. And I have no idea where to put that. Someone mentioned (in another thread) that it goes into a PersistentStoreCoordinator, however, I simply used the default Cocoa App Template with “Use Core Data for Storage” enabled. I had to create my own AppDelegate and never saw anything about a PersistentStoreCoordinator (and still don’t. I’ve tried creating a new app just to check). Any help here? I’m new to Cocoa but my app works perfectly fine without a PersistentStoreCoordinator, which is why I haven’t implemented one yet.. I do have an AppDelegate I created, but when I put this code in there it throws many errors. HELP :/

EDIT (for nick): Here is the new code:
enter image description here

And my header file:
enter image description here

  • 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-05-20T23:34:22+00:00Added an answer on May 20, 2026 at 11:34 pm

    Here you go: Core Data relevant header and methods.

    Application Delegate Header – Core Data relevant parts

    @interface CoreDataFirstStepsAppDelegate : NSObject <UIApplicationDelegate> 
    {    
         // ...
    @private
        NSManagedObjectContext *managedObjectContext_;
        NSManagedObjectModel *managedObjectModel_;
        NSPersistentStoreCoordinator *persistentStoreCoordinator_;
    }
    
    // ...
    
    @property (nonatomic, retain, readonly) NSManagedObjectContext *managedObjectContext;
    @property (nonatomic, retain, readonly) NSManagedObjectModel *managedObjectModel;
    @property (nonatomic, retain, readonly) NSPersistentStoreCoordinator *persistentStoreCoordinator;
    

    Application Delegate Implementation – Core Data relevant parts

    /**
     Returns the managed object context for the application.
     If the context doesn't already exist, it is created and bound to the persistent store coordinator for the application.
     */
    - (NSManagedObjectContext *)managedObjectContext {
    
        if (managedObjectContext_ != nil) {
            return managedObjectContext_;
        }
    
        NSPersistentStoreCoordinator *coordinator = [self persistentStoreCoordinator];
        if (coordinator != nil) {
            managedObjectContext_ = [[NSManagedObjectContext alloc] init];
            [managedObjectContext_ setPersistentStoreCoordinator:coordinator];
        }
        return managedObjectContext_;
    }
    
    
    /**
     Returns the managed object model for the application.
     If the model doesn't already exist, it is created from the application's model.
     */
    - (NSManagedObjectModel *)managedObjectModel {
    
        if (managedObjectModel_ != nil) {
            return managedObjectModel_;
        }
        NSString *modelPath = [[NSBundle mainBundle] pathForResource:@"CoreDataFirstSteps" ofType:@"momd"];
        NSURL *modelURL = [NSURL fileURLWithPath:modelPath];
        managedObjectModel_ = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL];    
        return managedObjectModel_;
    }
    
    
    /**
     Returns the persistent store coordinator for the application.
     If the coordinator doesn't already exist, it is created and the application's store added to it.
     */
    - (NSPersistentStoreCoordinator *)persistentStoreCoordinator {
    
        if (persistentStoreCoordinator_ != nil) {
            return persistentStoreCoordinator_;
        }
    
        NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"CoreDataFirstSteps.sqlite"];
    
        NSError *error = nil;
        persistentStoreCoordinator_ = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
        if (![persistentStoreCoordinator_ addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:nil error:&error]) {
    
            NSError *error;
            NSURL *storeURL = storeURL;
            NSPersistentStoreCoordinator *psc = persistentStoreCoordinator_;
            NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
                                     [NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,
                                     [NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil];
    
            if (![psc addPersistentStoreWithType:NSSQLiteStoreType
                                   configuration:nil
                                             URL:storeURL
                                         options:options 
                                           error:&error]) 
            {
                NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
                abort();
            }       
        }    
    
        return persistentStoreCoordinator_;
    }
    
    /**
     Returns the URL to the application's Documents directory.
     */
    - (NSURL *)applicationDocumentsDirectory {
        return [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a Mac app that can generate iphone ebook app project source
I have created a google-app-engine java project in Eclipse using Google's Eclipse plugin. My
I just starting as an Android app developer and I already have a problem
I have a Mac app that can double as a screensaver (a minor functionality,
I'm just building my Cocoa app for distribution on mac app store, but this
If you aren't familiar with Cinch, its an application on Mac App Store that
I have a mac with a custom PHP 5 install that built from about
I have Perl on Mac, Windows and Ubuntu. How can I tell from within
I have multiple installations of apache on my Mac OS X 10.5 and would
I have an iphone simulator running on my Mac. I have a .ipa file,

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.