Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

dispatch_async in NSManagedObjectContext's performBlock

According to the WWDC 2012 video, "Core Data Best Practices", dispatch_sync should be used to run some kind of callback in performBlock of context, which is created as a type of NSPrivateQueueConcurrencyType.

Why is that?

Can I use dispatch_async(dispatch_get_main_queue(), 0)... to call some UI-related callbacks in private queue's context's performBlock?

like image 736
minorblend Avatar asked Aug 15 '26 19:08

minorblend


1 Answers

No. NSPrivateQueueConcurrencyType manages it's own internal queue, and does not enjoy you trying to leave one of it's threads to do what you want to do (in fact, I believe it throws exceptions when this type of behavior occurs). There's a few ways of handling this, of course signalling semaphores being the more acceptable design pattern to get the truly "async feel", but as you note, dispatch_sync is usually the way to go.

like image 188
CodaFi Avatar answered Aug 17 '26 09:08

CodaFi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!