June 2016
Intermediate to advanced
214 pages
5h 40m
English
The API for handling bulk deletes was added to Core Data after bulk updates. Therefore the API is very similar.
| | func deleteOldRecipes() { |
| | guard let moc = writerContext else { |
| | fatalError("Writer context is nil") |
| | } |
| | |
| | moc.perform { |
| | let yOld = self.dateFrom1YearAgo() |
| | let fetch = NSFetchRequest<NSFetchRequestResult>(entityName: "Recipe") |
| | fetch.predicate = NSPredicate(format: "lastUsed <= %@", yOld as CVarArg) |
| | let request = NSBatchDeleteRequest(fetchRequest: fetch) |
| | request.resultType = .resultTypeObjectIDs |
| | |
| | do { |
| | guard let result = try moc.execute(request) |
| | as? NSBatchDeleteResult else { |
| | fatalError("Unexpected result from ... |
Read now
Unlock full access