/ Published in: Objective C

How do you delete all objects in an entity in Core Data? It's not as simple or straightforward as it is in SQL/SQLite. here's one reasonably quick way...
taken from stackoverflow
taken from stackoverflow
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
NSManagedObjectContext *myContext = [(<#YourAppDelegate#> *)[[NSApplication sharedApplication] delegate] managedObjecContext]; [fetchAllObjects setEntity:[NSEntityDescription entityForName:entity inManagedObjectContext:myContext]]; [fetchAllObjects setIncludesPropertyValues:NO]; //only fetch the managedObjectID // uncomment next line if you're NOT using ARC // [allObjects release]; if (error) { } [myContext deleteObject:object]; } if (![myContext save:&saveError]) { } return (saveError == nil); }
URL: http://stackoverflow.com/a/1383645/215494
Comments
