Roshanboy4u Roshanboy4u - 1 year ago 129
iOS Question

Core data deletion

What I have found in most of the solution for deleting all entries from core data is three step process
1. Fetch them all
2. Delete them all
3. Save them all,

Is there any alternative ..?

Answer Source
NSFetchRequest *requestDelete = [[NSFetchRequest alloc] initWithEntityName:@"Car"];
NSBatchDeleteRequest *deleteEntity = [[NSBatchDeleteRequest alloc] initWithFetchRequest:requestDelete];

NSError *deleteError = nil;
[myPersistentStoreCoordinator executeRequest:deleteEntity withContext:myContext error:&deleteError];

iOS 9 added a new class called NSBatchDeleteRequest that allows you to easily delete objects matching a predicate without having to load them all in to memory.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download