Rollback the coredata context while cancel after init the insert into entity || cancel the entity before save
Solution:
// MARK: - Rollback the context while cancel
func rollbackContext() {
if getContext().updatedObjects.count>0 {
getContext().rollback()
}
if getContext().insertedObjects.count>0 {
getContext().rollback()
}
}
// MARK: - Get the context
func getContext () -> NSManagedObjectContext {
var context: NSManagedObjectContext?
if #available(iOS 10.0, *) {
context = coredata.persistentContainer.viewContext
} else {
context = coredata.managedObjectContext
}
return context!
}
Comments
Post a Comment