iosobjective-ccore-datafast-enumerationmanagedobjectcontext

Is it safe to perform save operations on an NSManagedContext object when using Objective-C fast enumeration


I was wondering if this sort of code would be ok to use

NSManagedObjectContext *moc = [(AppDelegate*)[[UIApplication sharedApplication] delegate] managedObjectContext];
for (NSDictionary *dict in objects) {
            Object *object = [NSEntityDescription insertNewObjectForEntityForName:@"object"
                                                     inManagedObjectContext:moc];
            // Populate model fields with appropriate dictionary keys
        }

Reason why I ask is that you're advised to not pass references to a managed object context object across threads and wondering if that is indeed what is occurring here.


Solution

  • Fast enumeration using for (object in collection) has nothing to do with threads. All of this code runs on the same thread.