Skip to content

Instantly share code, notes, and snippets.

@MainasuK
Created March 14, 2020 15:18
Show Gist options
  • Save MainasuK/ec1fff2ceaeea193e8f79dbc9b73cceb to your computer and use it in GitHub Desktop.
Save MainasuK/ec1fff2ceaeea193e8f79dbc9b73cceb to your computer and use it in GitHub Desktop.
Bind NSTreeController contentArray to model
final class ViewModel: NSObject {
@objc var tree: [Node] = []
override init() {
super.init()
}
}
final class ViewController: NSViewController {
let viewModel = ViewModel()
private(set) lazy var treeController: NSTreeController = {
let treeController = NSTreeController()
// …
treeController.bind(
NSBindingName("contentArray"),
to: viewModel,
withKeyPath: #keyPath(LibraryOutlineViewModel.tree),
options: nil
)
return treeController
}()
}
@nezhyborets
Copy link

Do you think there is a way to have ViewModel that is non NSObject and still be able to do the binding?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment