문제

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.

도움이 되었습니까?

해결책

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

다른 팁

If that insert operation is threaded you should consider creating a backgrounded NSManagedObjectContext to handle it, which is a post way too big and answered on SO before.

performBlock:

You are using one ManagedObjectContext,the are no thread problem in your code. You are doing it the right way.All the code is sequential. If you want to use multiple context, each one in a thread, you should take care of multithreading.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top