Core Data and threads / Grand Central Dispatch

后端 未结 6 1285
臣服心动
臣服心动 2020-11-29 15:44

I\'m a beginner with Grand Central Dispatch (GCD) and Core Data, and I need your help to use Core Data with CGD, so that the UI is not locked while I add 40.000 records to C

6条回答
  •  渐次进展
    2020-11-29 16:44

    So the selected answer for this is from nearly 2 years ago now, and there's a few issues with it:

    1. It's not ARC friendly - need to remove release call on newMoc - ARC won't even compile with that
    2. You should be doing the weakSelf / strongSelf dance inside the block - otherwise you're probably creating a retain loop on the observer creation. See Apple's doc's here: http://developer.apple.com/library/ios/#documentation/cocoa/conceptual/ProgrammingWithObjectiveC/WorkingwithBlocks/WorkingwithBlocks.html
    3. @RyanG asked in a comment why he's blocking. My guess is because the recently edited method has waitUntilDone:YES - except that's going to block the main thread. You probably want waitUntilDone:NO but I don't know if there's UI updates firing from these change events as well so it would require testing.

    --Edit--

    Looking further into #3 - waitUntilDone:YES isn't a valid methodSignature for managed context objects, so how does that even work?

提交回复
热议问题