Skip to content

Instantly share code, notes, and snippets.

@chrisgibbs
Created April 27, 2012 21:24
Show Gist options
  • Save chrisgibbs/2513344 to your computer and use it in GitHub Desktop.
Save chrisgibbs/2513344 to your computer and use it in GitHub Desktop.
Deletes the persistent store file and re-creates a new one.
- (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