简体   繁体   English

在iPhone应用程序的Serial Queue中读取核心数据

[英]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. 当我在AppDelegate中创建串行队列并且此操作没有任何问题时,这运行得很好。

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 现在,当我尝试在UITableViewController中重新创建类似方案并在串行队列中执行相同方案时,当控件到达

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. 仅供参考,我将相同的ManagedObjectContext传递给串行队列。

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. 如果您的应用仅需要支持iOS 5+,那么您可以通过在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. 否则, 必须确保每个线程/队列都有其自己的上下文,并且仅将安全信息(如托管对象ID)从一个上下文传递到另一个。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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