iOS5 NSManagedObjectContext Concurrency types and how are they used?

后端 未结 3 1589
野的像风
野的像风 2021-02-02 00:49

Literature seems a bit sparse at the moment about the new NSManagedObjectContext concurrency types. Aside from the WWDC 2011 vids and some other info I picked up along the way,

3条回答
  •  终归单人心
    2021-02-02 01:39

    I think the answers are in the note : Core Data Release Notes for Mac OS X Lion http://developer.apple.com/library/mac/#releasenotes/DataManagement/RN-CoreData/_index.html

    For NSPrivateQueueConcurrencyType, I think you are not right. A child context created with this concurrency type will have its own queue. The parent/child context is not entirely related to threading. The parent/child seems to simplify communication between contexts. I understand that you just have to save changes in the child contexts to bring them back in the parent context (I have not tested it yet). Usually parent/child context pattern are related to main queue/background queue pattern but it is not mandatory. [EDIT] It seems that access to the store (Save and Load) are done via the main context (in the main queue). So it is not a good solution to perform background fetches as the query behind executeFetchRequest will always be performed in the main queue.

    For NSMainQueueConcurrencyType, it is the same as NSPrivateQueueConcurrencyType, but as it is related to main queue, I understand that you perform operation with the context without necesseraly using performBlock ; if you are in the context of the main queue, in View controller delegate code for example (viewDidLoad, etc).

提交回复
热议问题