Created
August 25, 2016 08:03
-
-
Save 3lvis/5514cb6ecd2291a9c998c0380ae0ed08 to your computer and use it in GitHub Desktop.
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
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) | |
} | |
} | |
} |
Good point!
I'l going to check that out
๐
๐
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Shouldn't this iterate? https://gist.github.com/3lvis/5514cb6ecd2291a9c998c0380ae0ed08#file-drop-swift-L2