Skip to content

Instantly share code, notes, and snippets.

@paulshapiro
Last active December 18, 2015 23:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paulshapiro/8261c7d82590b3fc5786 to your computer and use it in GitHub Desktop.
Save paulshapiro/8261c7d82590b3fc5786 to your computer and use it in GitHub Desktop.
// Grab the reference
NSPersistentStoreCoordinator *persistentStoreCoordinator = [NSPersistentStoreCoordinator MR_defaultStoreCoordinator];
// Get rid of stack reference first before deleting things or we may get a deadlock.
[MagicalRecord cleanUp];
// Tell persistent store coordinator to delete the stores it hangs onto
for (NSPersistentStore *store in persistentStoreCoordinator.persistentStores) {
NSError *error = nil;
[persistentStoreCoordinator removePersistentStore:store error:&error];
if (error) {
return;
} else {
}
}
// Get rid of persistent store file
NSString *storeFilename = [MagicalRecord defaultStoreName];
NSURL *storeFileURL = [NSPersistentStore MR_urlForStoreName:storeFilename];
NSError *deletionError = nil;
if ([[NSFileManager defaultManager] fileExistsAtPath:storeFileURL.path]) {
if (![[NSFileManager defaultManager] removeItemAtURL:storeFileURL error:&deletionError]) {
NSLog(@"Unresolved error deleting persistent store file: %@, %@", deletionError, [deletionError userInfo]);
abort();
}
} else {
DDLogError(@"There is no file at '%@'", storeFileURL);
return;
}
// Re-initialize stack
[MagicalRecord setupAutoMigratingCoreDataStack];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment