Do you know of any way to delete all of the entries stored in Core Data? My schema should stay the same; I just want to reset it to blank.
Edit
I'm looking to do this programmatically so that a user can essentially hit a reset
button.
Do you know of any way to delete all of the entries stored in Core Data? My schema should stay the same; I just want to reset it to blank.
Edit
I'm looking to do this programmatically so that a user can essentially hit a reset
button.
Works with all versions. Pass entity name and iterate through to delete all the entries and save the context.
Here is combined solution for purging Core Data.
As a quick reference to save searching elsewhere - recreating the persistent store after deleting it can be done with:
swift solution:
MagicalRecord makes this very easy.
If you want to go the delete all objects route (which is much simpler than tearing down the Core Data stack, but less performant), than this is a better implementation:
This implementation leverages
NSOperation
to perform the deletion off of the main thread and notify on completion. You may want to emit a notification or something within the completion block to bubble the status back to the main thread.