Skip to content

Instantly share code, notes, and snippets.

@richardbuckle
Created September 23, 2011 22:29
Show Gist options
  • Save richardbuckle/1238616 to your computer and use it in GitHub Desktop.
Save richardbuckle/1238616 to your computer and use it in GitHub Desktop.
Shut down a Core Data store prior to deleting the underlying file
- (void)closeDown {
NSArray *stores = [self.persistentStoreCoordinator persistentStores];
for (NSPersistentStore *store in stores) {
DebugLogging(@"Closing Core Data store at %@", [store URL]);
NSError *error = nil;
if (![self.persistentStoreCoordinator removePersistentStore:store error:&error]) {
DebugLogging(@"Unable to close Core Data store: error %@", [error localizedDescription]);
}
}
}
@mikeabdullah
Copy link

Is this because trying to remove the store after deleting it fails?

@richardbuckle
Copy link
Author

Core Data immediately gets v unhappy if you delete the file before closing down properly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment