Re: Swift with NSDocument and Revert To... browse all versions.
Quincey Morris
On Jul 23, 2018, at 23:02 , Quincey Morris <quinceymorris@...> wrote:
Well, dang, I got that wrong. (I “fixed” a typo in the email, forgetting to check that it actually worked.) You can’t use a KeyPath expression like “\WindowController.document.model” in Swift, because “document” has the wrong compile-time type. An alternative is to use ‘addObserver’ after all and specify a String keypath. Or, you can go ahead an make an extra document property of the correct type, like you did originally. Here’s a slightly cleaner way that can still use the ‘observe’ method:
This derived “windowDocument” property is correctly KVO compliant through its use of the “keyPathsForValuesAffecting<Key>” convenience method. It’s a bit of a mouthful, but it’s easier than doing a manual observation.
|
|