I've been reading apple documents and still there is a question, that a i can't find an answer for. I've got an UIManagedDocument object, which has two nested contexts - the child one on a main thread and a parent one on a private thread. And next, i've got a server side. So, when the data arrives from server i want to insert it into my managed document on a background thread.
Is it thread safe, to create an async queue, create there an NSManagedObjectContext and set as it's parent UIManagedDocument's child context which is created in a main thread?
dispatch_queue_t fetchQ = dispatch_queue_create("Data fetcher", NULL);
dispatch_async(fetchQ, ^{
//here goes some code for downloading data from the server
NSManagedObjectContext * backgroundContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSPrivateQueueConcurrencyType];
[backgroundContext setParentContext:self.eventDatabase.managedObjectContext]; // is this thread safe?
//some code for creating objects in backgroundContext
NSLog(@"inserting data in background thread");
});
dispatch_release(fetchQ);
In other words - is it thread safe to assign to a context that was created on a private thread parent, that was created on a main thread?