简体   繁体   中英

Concurrency in Core Data

I'm using the core data for fetching/ saving the data. In my application, I use 90 % of core data and 10 % with web services API. Currently, I'm working on optimization. Earlier I tried with NSOperationQueue and GCD operations. I found - performBlock: and - performBlockAndWait: to resolve the thread operations and asynchronous(background) process. This was more suitable for my code. I initiated managedobjectContext with concurrencytype as NSPrivateQueueConcurrencyType.

**Is it good to have NSPrivateQueueConcurrencyType alone throughout the application ? **

NSManagedObjectContext *private = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSPrivateQueueConcurrencyType];

It's OK to use NSPrivateQueueConcurrencyType everywhere. It might not be convenient but that's up to you.

The advantage of NSMainQueueConcurrencyType is that if your code is running on the main queue, you don't need performBlock or performBlockAndWait . Those methods would just run the block on the main queue, but when you're already on the main queue, that doesn't make a difference. This can make UI-related code simpler. Whether to use it is your call, depending on what you find convenient to do in your code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM