Application crashes when executing NSBatchDeleteRequest with "Unknown command type <NSBatchDeleteRequest, ..>"
I am writing an OS X application and it should be able to delete all instances of "SongEntity" stored in the master data store. However, when I try to execute NSBatchDeleteRequest, my application crashes with the following console output (excerpt):
Unknown command type (entity: SongEntity; predicate: ((zero)); sortDescriptors: ((null)); type: NSManagedObjectIDResultType;)>
Here is my implementation:
func clearStore() { let fetchRequest = NSFetchRequest(entityName: "SongEntity") let deleteRequest = NSBatchDeleteRequest(fetchRequest: fetchRequest) do { try managedObjectContext.executeRequest(deleteRequest) } catch { fatalError("Not able to perform operation: \(error)") } managedObjectContext.reset() } Any help would be greatly appreciated
EDIT: It turns out this problem is related to the selected storage type: From the NSBatchDeleteRequest class:
// May not be supported by all store types. I tried changing the storage type from NSXMLStoreType (default macOS template) to NSSQLiteStoreType , and now it works.
+5