Created
December 4, 2018 03:55
-
-
Save thepost/3de48077769714d549e3c8e8ae7d114a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension ModelController { | |
func delete(by objectID: NSManagedObjectID) { | |
let managedObject = context.object(with: objectID) | |
context.delete(managedObject) | |
} | |
func delete<M: NSManagedObject>(_ type: M.Type, predicate: NSPredicate?=nil) { | |
if let objects = fetch(type, predicate: predicate) { | |
for modelObject in objects { | |
delete(by: modelObject.objectID) | |
} | |
} | |
if context.deletedObjects.count > 0 { | |
save() | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment