I'm trying to bind the state of a NSButton
to an objectController
, but I can't find in Interface Builder the Voice "State" under Binds for the button.
Is there a way to bind this property?
I assume this is a checkbox-style NSButton
? Bind to its "value" in IB.
In case anyone wants to do two-way binding between NSButton
's state and, say, NSUserDefaultsController
in Swift 2, here's how you can do this. All kudos to this answer.
var button: NSButton!
let userDefaults: NSObject = NSUserDefaultsController.sharedUserDefaultsController().values as! NSObject
let options: [String:AnyObject] = [NSContinuouslyUpdatesValueBindingOption: true]
button.cell!.bind("state", toObject: userDefaults, withKeyPath: "MyButtonState", options: options)
userDefaults.bind("MyButtonState", toObject: button.cell!, withKeyPath: "state", options: options)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With