Bringing UIManagedDocument to OS X?

萝らか妹 提交于 2019-12-11 08:17:12

问题


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?

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


回答1:


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.

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.



来源:https://stackoverflow.com/questions/12294201/bringing-uimanageddocument-to-os-x

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!