4

to : をNSManagedObjectContext使用して、レシーバーの (メイン) キュー以外のキューでブロックを実行できることに気付きました。NSMainQueueConcurrencyTypeperformBlockAndWait

たとえば、次のコードでは、 myが typeで myがtypeの場合、 のキューparentContextでブロックが実行されます。childContextparentContextNSMainQueueConcurrencyTypechildContextNSPrivateQueueConcurrencyType

[childContext performBlockAndWait:^{
    //Thread 1, Queue: NSManagedObjectContext Queue
    [parentContext performBlockAndWait:^{
        //Thread 1, Queue: NSManagedObjectContext Queue
        //This is the same queue as the child context's queue
    }];
}];

対照的に、次のコードは期待どおりに機能しparentContextます。my はメイン キューでブロックを実行します。

[childContext performBlock:^{
    [parentContext performBlockAndWait:^{
        //Thread 1, Queue: com.apple.main-thread
    }];
}];

これは予想される動作ですか?ドキュメントの状態以来、それは確かに私を混乱させています"performBlockAndWait: synchronously performs a given block on the receiver’s queue."

4

1 に答える 1