-
-
Save paulshapiro/8261c7d82590b3fc5786 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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