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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:33:26+00:00 2026-05-27T18:33:26+00:00

we are using core data for our online catalog and its working fine and

  • 0

we are using core data for our online catalog and its working fine and app available in app store now I need to upgrade the core date with some of fields and attributes. It migrated to new one but old data already stored in the app are completely vanished. I tried various ways to retain it using this code

    NSString *databaseFilePath = [[self applicationDocumentsDirectory] stringByAppendingPathComponent: @"App_iOS.sqlite"];

    NSFileManager *fileManager = [NSFileManager defaultManager];
    [fileManager removeItemAtPath:databaseFilePath error:NULL];

    NSURL *storeUrl = [NSURL fileURLWithPath: databaseFilePath];

    NSError *error = nil;
    if( ![[self persistentStoreCoordinator] addPersistentStoreWithType:NSSQLiteStoreType  configuration: nil URL:storeUrl options:nil error:&error])
    {
        [__managedObjectContext insertObjects];
    }
    else
    {
        [__managedObjectContext updatedObjects];
    } 

I am not get solution yet to retain the data in app. I searched in internet for this most of the face the same problem but I am not receive the good solution yet

  • 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-27T18:33:27+00:00Added an answer on May 27, 2026 at 6:33 pm

    I’ve now found out that this is quite simple – once you know where to look.#
    In my AppDelegate I set-up the NSPersistentStoreCoordinator – and you need to add some options to this to tell it to handle auto-migrate:

        NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
    
        [NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,
    
        [NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil];
    
        NSError *error;
        _persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel: [self managedObjectModel]];
    
        if (![_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType        configuration:nil URL:storeUrl options:options error:&error]) {
              // Handle error
            NSLog(@"Problem with PersistentStoreCoordinator: %@",error);
        }
    

    Then you need to do in xCode:

    1.  Select your xcdatamodeld file
    2.  Select the Editor Menu at the top - then choose Add Model Version
    3.  Now your xcdatamodeld file have two (modelname.xcdatamodel & modelname2.xcdatamodel ) .
    4.  Now modelname.xcdatamodel  have the green check mark implies it is current version, but we need to change the modelname2.xcdatamodel as a current version
    5.  Select the xcdatamodeld file and then select the View Menu at the top - then Choose Utilities - then Choose the Show File Inspector is shown in right side of Xcode and then Select the Versioned Core Data Model - have Current(DropDownList) - select modelname2(the one you just made current version have green check mark).
    6.  Now when you install this version onto a device that has the old model - it will automatically upgrade that model to the new model.
    

    This seems great and as simple as I wanted – but I think you need to be careful during development as you change a model – otherwise you will have to create a new version for each change.

    I think what I will do is that I will keep all of the changed files and then once I get ready to deploy my update I’ll delete all the in-between files and just deploy with the oldest and latest models.

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

Sidebar

Related Questions

I am using core data in my app. My app was working fine.. I
I have developed my app using core data. It works fine in the simulator.
I'm using core data in my app. I have two entities that are related:
I've been creating an iPhone App using Core Data. First of all, does it
I'm designing an iPad/iPhone app using core data. The main focus of the app
Using Core Data w/a sqlite store on iPhone.... I've got a bunch of comic
I'm working on my 2nd iPhone app and am curious about Core Data. Time
I am using a custom NSValueTransformer to store color information in my Core Data
I'm considering using Core Data for an app I'm writing. However, after reading the
I have some Core Data functionality that was working fine until some recent (seemingly

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.