简体   繁体   中英

Read Core data in Serial Queue for iPhone app

I have an app which uses Core data and the values are fetched from a link on internet.

This runs absolutely fine when I am creating a serial queue in AppDelegate and I am not facing any problem with the same.

Now, when I am trying to re-create similar scenario in a UITableViewController and executing the same in a serial queue but when the control reaches

NSError *error;
NSArray *match = [context executeFetchRequest:fetchRequest error:&error];

execution control disappears and then this code remains in the execution till eternity.

Can anyone help me with what exactly is wrong here?

FYI, I am passing the same ManagedObjectContext to the serial queue.

The last sentence may be the key: managed object contexts are not designed to be used by more than one thread/queue. See the concurrency section in the Core Data Programming Guide for more on that. If your app only needs to support iOS 5+, then you may be able to solve this (and get out of managing your own serial queue) with the new private queue context added in 5.0. Otherwise, you must ensure that each thread/queue has its own context, and that you only pass safe information (like managed object IDs) from one context to another.

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