将UIManagedDocument带到OS X? [英] Bringing UIManagedDocument to OS X?

查看:234
本文介绍了将UIManagedDocument带到OS X?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在基于Core Data文档的应用程序中实现异步保存。我的 NSDocument 子类的图案就像iOS的 UIManagedDocument 与一对 NSManagedObjectContext 实例,一个用于具有父上下文的主线程用于后台保存。

I'll need to implement asynchronous saving in a Core Data document-based application. My NSDocument subclass is patterned just like iOS' UIManagedDocument with a pair of NSManagedObjectContext instances, one for the main thread with a parent context for background saving.

问题是每当我的文档,应用程序总是显示一个提示:

The problem is that whenever I the document, the app always displays a prompt:


无法保存文档...。该文件已被另一个应用程序更改。

The document ... could not be saved. The file has been changed by another application.

我不知道我的实现缺少什么?

I wonder what is missing from my implementation? How can I make the dialog above go away whenever I save?

您可以在此提示中找到我的 NSDocument 子类别: https://gist.github.com/3652120

You can find my NSDocument subclass in this gist: https://gist.github.com/3652120

推荐答案

显然,克隆 UIManagedDocument 的功能并不难。一个警告是确保 NSDocument 的文件的日期的概念更新每当主线程的上下文保存。第二个警告是使用主线程管理对象上下文的undo管理器。

Apparently cloning the functionality of UIManagedDocument isn't too hard. One caveat is to make sure that the NSDocument's notion of the file's date is updated whenever the main thread's context is saved. The second caveat is to use the main thread managed object context's undo manager.

请参阅将异步核心数据文档导入OS X 有关如何执行此操作的信息和示例 NSDocument 子类代码如何做它。

Refer to Bringing Asynchronous Core Data documents to OS X for information on how to do this and sample NSDocument subclass code how to do it.

这篇关于将UIManagedDocument带到OS X?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆