Search code examples
iosobjective-ccore-datansfetchrequest

Core Data: How to fault freshly created managed objects


I am creating new managed objects in a loop, save them and would like to fault them right after saving them to reduce the RAM footprint.

This is how I create the managed objects:

[objects enumerateObjectsUsingBlock:^(PFObject *obj, NSUInteger idx, BOOL *stop) {
   @autoreleasepool {
   ForexHistory *forexHistory = [NSEntityDescription insertNewObjectForEntityForName:localEntityName 
   inManagedObjectContext:backgroundContext];
   forexHistory.date = obj[@"date"];
   }
}];
NSError *saveError = nil;
[backgroundContext save:&saveError];

In order to fault the objects, I understand that I need to use refreshObjects:mergeChanges.

Do I need to refetch all inserted objects in order to iterate over them and send refreshObjects:mergeChanges:NO to each of them or is there a better way?


Solution

  • I do not know, whether I understood your question correct.

    You can wipe-out a moc with -reset. All references to objects become invalid. You have to refetch them.