Roshanboy4u Roshanboy4u - 3 months ago 60
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 ..?

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.