Created
October 2, 2014 13:30
-
-
Save jrturton/89ce72a87e1b0661eccb to your computer and use it in GitHub Desktop.
Removing a core data store
This file contains hidden or 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)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