Skip to content

Instantly share code, notes, and snippets.

@jrturton
Created October 2, 2014 13:30
Show Gist options
  • Save jrturton/89ce72a87e1b0661eccb to your computer and use it in GitHub Desktop.
Save jrturton/89ce72a87e1b0661eccb to your computer and use it in GitHub Desktop.
Removing a core data store
-(void)removeDataStoreAtURL:(NSURL*)url
{
// Need to remove anything matching the first part - there are also logging files alongside the SQLite file itself.
// Typical directory contents are:
// Name.sqlite, Name.sqlite-shm, Name.sqlite-wal
NSURL *folderURL = [url URLByDeletingLastPathComponent];
NSArray *contents = [[NSFileManager defaultManager] contentsOfDirectoryAtURL:folderURL includingPropertiesForKeys:nil options:0 error:nil];
for (NSURL *fileURL in contents)
{
NSString *filename = [fileURL lastPathComponent];
if ([filename hasPrefix:[url lastPathComponent]])
{
[[NSFileManager defaultManager] removeItemAtURL:fileURL error:nil];
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment