Created
March 14, 2020 15:18
-
-
Save MainasuK/ec1fff2ceaeea193e8f79dbc9b73cceb to your computer and use it in GitHub Desktop.
Bind NSTreeController contentArray to model
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
}() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Do you think there is a way to have ViewModel that is non NSObject and still be able to do the binding?