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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T23:24:39+00:00 2026-05-30T23:24:39+00:00

When I update my app, I’m doing some stuff with my CoreData model on

  • 0

When I update my app, I’m doing some stuff with my CoreData model on startup and afterwards I replace the .sqlite file the persistent store uses with:

NSArray *stores = [__persistentStoreCoordinator persistentStores];

for(NSPersistentStore *store in stores) {
    [__persistentStoreCoordinator removePersistentStore:store error:nil];
    [[NSFileManager defaultManager] removeItemAtPath:store.URL.path error:nil];
}
__persistentStoreCoordinator = nil;
[self persistentStoreCoordinator];

__managedObjectContext = nil;
[self managedObjectContext];

Everything works fine, just the way it is suposed to. But when I close the app via the homebutton, it crashes:

[NSPersistentStoreCoordinator retain]: message sent to deallocated instance

I’m using ARC … actually you could say it doesn’t matter, because it crashes when being closed, so you don’t notice the crash. But, of course, that’s not an option and there has to be a right way to do that!?

Any ideas? Why is there a retain sent to the NSPersistenStoreCoordinator? It has something to do with __persistentStoreCoordinator = nil; but I need to nil it, otherwise it doesn’t use the new .sqlite.

Cheers!

  • 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-30T23:24:40+00:00Added an answer on May 30, 2026 at 11:24 pm

    Well finaly I found a better (and working) way to replace the .sqlite & storeCoordinator’s store, without the need to nil the persistentStoreCoordinator:

    NSArray *stores = [__persistentStoreCoordinator persistentStores];
    
    for(NSPersistentStore *store in stores) {
        [__persistentStoreCoordinator removePersistentStore:store error:nil];
        [[NSFileManager defaultManager] removeItemAtPath:store.URL.path error:nil];
    }
    
    NSString *storePath = [[self applicationDocumentsDirectoryString] stringByAppendingPathComponent:@"PictureApp.sqlite"];
    
    NSURL *storeUrl = [NSURL fileURLWithPath:[[self applicationDocumentsDirectoryString] stringByAppendingPathComponent:@"PictureApp.sqlite"]];
    
    NSString *defaultStorePath = [[NSBundle mainBundle] pathForResource:@"PictureApp" ofType:@"sqlite"];
    if (defaultStorePath) {
        [[NSFileManager defaultManager] copyItemAtPath:defaultStorePath toPath:storePath error:NULL];
    }
    
    NSError *error = nil;
    [__persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeUrl options:options error:&error];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I push an app update to the app store, but choose I will
I am making an app for some people and they want to instantly update
What happens when I update an app that has some files stored in the
when the user clicks on cab file to update the app, I would like
Hi I have an existing app in App store, I would like to update
I'm trying to update a value in my app.config file using the code below
I have an asp.net update web app. Users go the the page, hit the
I am trying to update my iPhone app to work with OS 3.0. I
I have made an update on Google App Engine with a small fix and
(update) ICustomTypeDescriptor works for my Windows Forms app, but not for Silverlight; Not supported.

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.