Skip to content

Instantly share code, notes, and snippets.

@tonyarnold
Created June 26, 2012 13:52
Show Gist options
  • Save tonyarnold/2995892 to your computer and use it in GitHub Desktop.
Save tonyarnold/2995892 to your computer and use it in GitHub Desktop.
Deleting all entities in your NSManagedObjectContext using MagicalRecord
NSArray *allEntities = [NSManagedObjectModel MR_defaultManagedObjectModel].entities;
[allEntities enumerateObjectsUsingBlock:^(NSEntityDescription *entityDescription, NSUInteger idx, BOOL *stop) {
[NSClassFromString([entityDescription managedObjectClassName]) MR_truncateAll];
}];
@medvedNick
Copy link

medvedNick commented Oct 26, 2018

for everyone who likes copy-pasting as much as I do:

if let all = NSManagedObjectModel.mr_default().entities {
    for entity in all {
        _ = NSClassFromString(entity.managedObjectClassName)?.mr_truncateAll()
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment