Create a background theme for recording master data

I am trying to recreate the tri-core kernel data system described in this article on cocoenetics ( http://www.cocoanetics.com/2012/07/multi-context-coredata/ ). The problem I am facing is creating a private MOC in my background thread. I do not have much experience with multithreading and how this should be done in the lens c. I read articles and tried to figure out how to correctly implement this approach, but I finally admitted that I did not know what I was doing.

To create this approach, do I need to create and manage NSThread? Or is there an easier way that I don't understand?

+4
source share
2 answers

The easiest way to perform basic data operations in the background is to create an NSPrivateQueueConcurrencyType managed entity NSPrivateQueueConcurrencyType . This type of MOC creates and manages a private queue. Using performBlock or performBlockAndWait to perform operations with a private MOC ensures that the right queue is used.

See Concurrency Support for managed entity contexts in the master data release notes for OS X v10.7 and iOS 5.0 for more details and examples.

I can only recommend watching videos or slides from the 303 WWDC 2011 session "οΏΌWhats New in Core Data on iOS", which explains Core Data concurrency.

+5
source

Flow control is very simple in iOS

To make something run in the background, you do the following:

 - (void)someMethod { // method is called on main thread normally dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ .... // here things are run in background }); } 

To return to the main thread anywhere, do the following:

 - (void)someOtherMethod { // method is called on background thread dispatch_async(dispatch_get_main_queue(), ^{ ... // here things are on main thread again }); } 
-3
source

All Articles