NSOperation 内的 ASINetworkQueue 保存核心数据时出错
我想在 NSOperation 中使用 ASINetworkQueue。这效果很好并且没有任何问题。失败的是保存核心数据。我为此操作设置了一个新的 NSManagedObjectContext,就像文档中所说的那样。
我认为问题是我在 ASINetworkQueue 完成并调用委托选择器时保存数据。由于在主线程上调用委托,因此保存消息失败。
这可能是问题所在吗?有人有解决方案吗?
I want to use the ASINetworkQueue inside an NSOperation. This works great and makes no problem. What fails is saving Core Data. I set up a new NSManagedObjectContext for this Operation like it is told in the docs.
I think that the problem is that I save the data when the ASINetworkQueue finishes and delegate selector is called. Because the delegates are called on the mainThread, the save message fails.
Can this be the problem and does anybody has a solution?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在使用 PerformSelectorOnMainThread 方法吗(合并新实例化的 ManagedObjectContext 中的更改)?
我在我的操作中做了类似的事情(ctx是我实例化的MOC):
首先注册通知:
然后当您需要保存上下文时:
然后是与主MOC合并的方法:
希望这有帮助
You are using the PerformSelectorOnMainThread method right (to merge the changes from the new instantiated ManagedObjectContext)?
I do something like this in my Operations (ctx is my instantiated MOC):
First register for notifications:
Then when you need to save the context:
And then the method that does the merging with the main MOC:
Hope this helps