Created
April 2, 2015 19:48
-
-
Save binho/e8d0109dc48741940ef4 to your computer and use it in GitHub Desktop.
MagicalRecord remove and reset CoreData
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
- (void)resetCoreData { | |
DDLogInfo(@"[RESET-COREDATA] Started."); | |
[MagicalRecord cleanUp]; | |
NSURL *storeURL = [NSPersistentStore MR_urlForStoreName:kMobilStoreName]; | |
NSURL *walURL = [[storeURL URLByDeletingPathExtension] URLByAppendingPathExtension:@"sqlite-wal"]; | |
NSURL *shmURL = [[storeURL URLByDeletingPathExtension] URLByAppendingPathExtension:@"sqlite-shm"]; | |
NSError *error = nil; | |
BOOL hadSuccess = YES; | |
for (NSURL *url in @[storeURL, walURL, shmURL]) { | |
if ([[NSFileManager defaultManager] fileExistsAtPath:url.path]) { | |
hadSuccess = [[NSFileManager defaultManager] removeItemAtURL:url error:&error]; | |
} | |
} | |
if (hadSuccess) { | |
DDLogInfo(@"[RESET-COREDATA] Reset OK, recreating..."); | |
[MagicalRecord setupCoreDataStackWithStoreNamed:kMobilStoreName]; | |
} | |
else { | |
DDLogError(@"[RESET-COREDATA] An error has occurred while deleting %@ error: %@", kMobilStoreName, error); | |
} | |
DDLogInfo(@"[RESET-COREDATA] Finished"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment