Skip to content

Instantly share code, notes, and snippets.

Embed
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 fetchRequestWithEntityName:desc.name];
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
You can’t perform that action at this time.