Created
April 27, 2012 21:24
-
-
Save chrisgibbs/2513344 to your computer and use it in GitHub Desktop.
Deletes the persistent store file and re-creates a new one.
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)resetPersistentStore | |
{ | |
NSURL *storeURL = [NSURL fileURLWithPath:[[NSString documentsPath] stringByAppendingPathComponent:DatabaseFileName]]; | |
// Remove persistent store from the coordinator | |
NSPersistentStore *store = [_persistentStoreCoordinator persistentStoreForURL:storeURL]; | |
NSError *error = nil; | |
if (![_persistentStoreCoordinator removePersistentStore:store error:&error]) | |
{ | |
// handle error | |
return; | |
} | |
// Delete database file | |
[[DTAsyncFileDeleter sharedInstance] removeItemAtURL:storeURL]; | |
// Create new persistent store | |
error = nil; | |
[_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType | |
configuration:nil | |
URL:storeURL | |
options:nil | |
error:&error]; | |
if (error) | |
{ | |
// handle error | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment