(iOS Swift) How can I rebuild/reset Core Data?

I am trying to rebuild/reset core data after a failed lightweight migration. There seems to be a lot of documentation on how to do this with objective-c, most of which points to http://pinkstone.co.uk/how-to-tear-down-your-core-data-stack/, but I haven't been able to find anything for Swift. Additionally, I have had my "go" at it, and have gotten a couple errors as per my question on SO at http://stackoverflow.com/questions/37314254/errors-rebuilding-resetting-core-data


Has anyone been able to successfully rebuild/reset core data with Swift?

Answered by mckamike in 139987022

Will be further testing - but right now it's working when handling a failed migration after changing a relationship from to-many to a to-one. My SO post as the updated solution.

Accepted Answer

Will be further testing - but right now it's working when handling a failed migration after changing a relationship from to-many to a to-one. My SO post as the updated solution.

You want this from NSPersistentStoreCoordinator:


/ delete or truncate the target persistent store in accordance with the store class's requirements. It is important to pass similar options as addPersistentStoreWithType: ... SQLite stores will honor file locks, journal files, journaling modes, and other intricacies. It is not possible to unlink a database file safely out from underneath another thread or process, so this API performs a truncation. Other stores will default to using NSFileManager.

*/

- (BOOL)destroyPersistentStoreAtURL:(NSURL *)url withType:(NSString *)storeType options:(nullable NSDictionary *)options error:(NSError**)error API_AVAILABLE(macosx(10.11),ios(9.0));

(iOS Swift) How can I rebuild/reset Core Data?
 
 
Q