adib
adib

Reputation: 8395

Bringing UIManagedDocument to OS X?

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

Upvotes: 1

Views: 602

Answers (1)

adib
adib

Reputation: 8395

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.

Upvotes: 1

Related Questions