In my mac app, [Model m] is a custom object with a synthesized BOOL property and ivar rollAnimations. And animationsItem is an NSMenuItem object. I want to bind the state of my animationsItem to the rollAnimations property and ivar of [Model m]. A two-way binding would be ideal (so that changing either property changes the other), but if that's messy (retain cycles and such), I'll settle for a one-way binding, such that changing the menu item changes the rollAnimations property.
Here is a code snippet. It's not working. What am I missing?
NSMutableDictionary *bindingOptions = [NSMutableDictionary dictionary];
NSNumber *yesNumber = [NSNumber numberWithBool:YES];
[bindingOptions setObject:yesNumber forKey:NSValidatesImmediatelyBindingOption];
[animationsItem bind:@"state" toObject:[Model m] withKeyPath:@"rollAnimations" options:bindingOptions];
The Cocoa Bindings Reference lists all the bindings a menu item supports. The one you want is
@"value"
, not@"state"
. (This goes for buttons, too, by the way.)