Skip to content

Instantly share code, notes, and snippets.

@3lvis
Created August 25, 2016 08:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 3lvis/5514cb6ecd2291a9c998c0380ae0ed08 to your computer and use it in GitHub Desktop.
Save 3lvis/5514cb6ecd2291a9c998c0380ae0ed08 to your computer and use it in GitHub Desktop.
public func drop() throws {
guard let store = self.persistentStoreCoordinator.persistentStores.last, storeURL = store.URL, storePath = storeURL.path
else { throw NSError(info: "Persistent store coordinator not found", previousError: nil) }
let sqliteFile = (storePath as NSString).stringByDeletingPathExtension
let fileManager = NSFileManager.defaultManager()
self._writerContext = nil
self._mainContext = nil
self._persistentStoreCoordinator = nil
let shm = sqliteFile + ".sqlite-shm"
if fileManager.fileExistsAtPath(shm) {
do {
try fileManager.removeItemAtURL(NSURL.fileURLWithPath(shm))
} catch let error as NSError {
throw NSError(info: "Could not delete persistent store shm", previousError: error)
}
}
let wal = sqliteFile + ".sqlite-wal"
if fileManager.fileExistsAtPath(wal) {
do {
try fileManager.removeItemAtURL(NSURL.fileURLWithPath(wal))
} catch let error as NSError {
throw NSError(info: "Could not delete persistent store wal", previousError: error)
}
}
if fileManager.fileExistsAtPath(storePath) {
do {
try fileManager.removeItemAtURL(storeURL)
} catch let error as NSError {
throw NSError(info: "Could not delete sqlite file", previousError: error)
}
}
}
@elland
Copy link

elland commented Aug 25, 2016

@3lvis
Copy link
Author

3lvis commented Aug 25, 2016

Good point!

@3lvis
Copy link
Author

3lvis commented Aug 25, 2016

I'l going to check that out

@elland
Copy link

elland commented Aug 25, 2016

👍
💓

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment