Re: Swift with NSDocument and Revert To... browse all versions.
Quincey Morris
On Jul 13, 2018, at 03:49 , Bill Pitcher <bill@...> wrote:
Well, things get more complicated when you use non-Obj-C types, but it’s not necessarily true that you can’t use Swift types. In the case of the model, it may be sufficient that your “model" property of NSDocument be @objc (but not a Swift-native type), to KVO-observe it.
It’s still an @obj property of an Obj-C object, so it’s observable. The type is actually ‘id’, which translates into Swift ‘Any’ or ‘Any?’ these days, not into ‘AnyObject’ as it used to.
I wasn’t really saying that, just saying you should be able to use KVO to keep track of the model’s root object. Whether you use KVO or Obj-C compatible objects or properties further down the line is up to you. Note, however, that there is still a *lot* in built-in pressure to stay Obj-C-compatible in this part of your app design, because a lot of familiar design patterns rely on KVO and KVC. |
|