NSOperation VS GCD for Core-Data

What is more suitable for a situation when data needs to be stored in Core-Data in one stream and read from Core-Data to another?

I was thinking about GCD, but how does it work with creating NSManagedObjectContext for each thread? How to create these objects in a queue?

The data warehouse needs to be updated / synchronized when changes were made in different threads, is it better to do this with GCD or NSOperation?

I would like to be able to simply transfer the blocks to 2 queues when reading and writing to the data warehouse as needed, without problems with damage to the storage or with different versions of the storage.

+5
source share
2 answers

GCD NSOperation , .

NSOperationQueue GCD, .

GCD , NSOperationQueue.

, CoreData , . iOS 5, concurrency MOC. , .

, MOC NSPrivateQueueConcurrencyType , Core Data. , , persistentStoreCoordinator . ( ).

, ...

NSManagedObjectContext *moc = [[NSManagedObjectCotext alloc] initWithConcurrencyType:NSPrivateQueuqConcurrencyType];
moc.parentContext = contextIWantToBeParent;
moc.persistentStoreCoordinator = pscIWant;

[moc performBlock:^{
    // Your MOC stuff running on its own private queue
}];

, ( MOC, PSC).

performBlock.

. , NSManagedObject . NSManagedObjects ? - 3

, . , MOC concurrency, , .

, , concurrency:

  • NSConfinementConcurrencyType, , .

  • NSPrivateQueueConcurrencyType, MOC performBlock performBlockAndWait.

  • NSMainQueueConcurrencyType, MOC performBlock, performBlockAndWait , .

, MOC .

, performBlock, API- Core Data API , .

+16

All Articles