Re: Swift with NSDocument and Revert To... browse all versions.


Bill Pitcher
 

Firstly I’ve uploaded a very cut down project which shows the problem.
https://www.ilike.co.nz/downloads/testDocument.zip

"Propagate the data reversion to your window controller and view controllers can be difficult, because any setup you did in windowDidLoad/viewDidLoad is not automatically redone.”
I found that the didLoad methods are called before the .document property has content. In windowDidLoad .document in nil.

"It can be especially confusing when the document (and the data model it provides/contains) is reverted, but individual references within you controller hierarchy refer to (and keep alive) various bits of the data model objects that were supposed to be discarded.”
Yes!

"It’s also possible to be propagating the model data correctly to the view controllers, but still have the wrong information showing in the views because the propagation wasn’t fully KVO compliant.”

My swift Objects are not KVO at all, I’m not using KVO. But I’m also seeing the same behaviour in my swift NSPersistentDocument and CoreData classes, and the Apple Demo App “PackagedDocumentforOSX”

"There probably isn’t a simple way to solve this, other than the brute force approach of tracking the model data through the controllers to make sure it’s all being updated when necessary.”
This is the problem, I can’t find a point in the where I can brute force the updates. The document didSet is called before the Window is displayed on the restored data. I would have thought that the didSet on WindowController.documet was the same a putting KVO on the property in viewDidLoad.

I find it crazy that using Swift the process of getting NSDocument data onto the screen and back again with Revert To… seems to me to be broken.


Bill Pitcher
bill@...

On 13/07/2018, at 12:36 PM, Quincey Morris <quinceymorris@...> wrote:

On Jul 12, 2018, at 03:37 , Bill Pitcher <bill@...> wrote:

After returning from Revert To... restoring an old document, my document flicks back to displaying the original data when went into the version browser, BUT the backing document has been resorted correctly. Doing an UpdateMyControls in windowDidExitVersionBrowser does a bad visual, from new to old then new again.
Propagate the data reversion to your window controller and view controllers can be difficult, because any setup you did in windowDidLoad/viewDidLoad is not automatically redone. It can be especially confusing when the document (and the data model it provides/contains) is reverted, but individual references within you controller hierarchy refer to (and keep alive) various bits of the data model objects that were supposed to be discarded.

It’s also possible to be propagating the model data correctly to the view controllers, but still have the wrong information showing in the views because the propagation wasn’t fully KVO compliant.

There probably isn’t a simple way to solve this, other than the brute force approach of tracking the model data through the controllers to make sure it’s all being updated when necessary.

Join cocoa@apple-dev.groups.io to automatically receive all group messages.