Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Delete all objetcts in a MOC
NSArray *entities = self.managedObjectContext.persistentStoreCoordinator.managedObjectModel.entities;
for (NSEntityDescription *desc in entities)
NSFetchRequest *allObjectsRequest = [NSFetchRequest];
NSError *fetchError;
NSArray *allObjects = [self.managedObjectContext executeFetchRequest:allObjectsRequest error:&fetchError];
if (allObjects)
for (NSManagedObject *obj in allObjects)
[obj.managedObjectContext deleteObject:obj];
[self.managedObjectContext saveChanges];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment