I have the above CoreData scheme. How can i delete everything in it ? Is there an easy and quick way ?
Update:
Ok i try this
func flushDatabase() {
if let moc = self.managedObjectContext{
moc.lock()
if let stores = persistentStoreCoordinator?.persistentStores as? [NSPersistentStore] {
for store in stores {
persistentStoreCoordinator?.removePersistentStore(store, error: nil)
if let path = store.URL?.path {
NSFileManager.defaultManager().removeItemAtPath(path, error: nil)
}
}
}
moc.unlock()
}
}
But how i recreate the persistenStoreCoordinator ?
Update 2
class func deleteAllMinigames(context:NSManagedObjectContext) {
context.lock()
let fetchRequest = NSFetchRequest(entityName: "Minigame")
// fetchRequest.includesSubentities = true
// fetchRequest.includesPropertyValues = false
var error: NSError?
if let items = context.executeFetchRequest(fetchRequest, error: &error) as? [Minigame]{
for item in items {
if item.validateForDelete(&error){
context.deleteObject(item)
}else{
println(error?.localizedDescription)
}
}
}
context.unlock()
}
When i trying to delete all minigames i get this. I tried to make all delete to rules to cacsade but its not working
*Optional("The operation couldn’t be completed. (Cocoa error 1560.)")
Optional("The operation couldn’t be completed. (Cocoa error 1560.)")
Optional("The operation couldn’t be completed. (Cocoa error 1560.)")
Optional("The operation couldn’t be completed. (Cocoa error 1560.)")
Optional("The operation couldn’t be completed. (Cocoa error 1560.)")
Optional("The operation couldn’t be completed. (Cocoa error 1560.)")*