>> Why are bindings A, B, C and D bidirectional but E is only unidirectional? > > Regarding A, B, C and D: Apparently, NSButton's implementation of bind:::: > sets up observers in both directions when binding to the "value" binding.
This isn't what happens, run the following code: > static NSString *const PropertyKey = @"somethingEnabled"; > > NSMutableDictionary *model = [NSMutableDictionary > dictionaryWithObjectsAndKeys: > (id)kCFBooleanFalse, > PropertyKey, > nil]; > > NSButton *button = [[NSButton alloc] initWithFrame:CGRectMake(0., 0., 100., > 27.)]; > [button setButtonType:NSSwitchButton]; > [button bind:NSValueBinding toObject:model withKeyPath:PropertyKey > options:nil]; with a breakpoint set on -[NSObject addObserver:forKeyPath:options:context:] and you'll see that -addObserver:forKeyPath:options:context: is only called once from inside -bind:… What NSButton does when it needs to change the value of it's bound to counterpart, is introspect the binding either through -infoForBinding: (or other means depending on where it stored the captured binding information, we'll assume the -infoForBinding: case for simplicity). It extracts the bound-to object (stored under NSObservedObjectKey), and the keypath (stored under NSObservedKeyPathKey) and invokes [observedObject setValue:newValue forKeyPath:observedKeyPath]. (NSValueTransformer code left out for brevity). Keith _______________________________________________ Cocoa-dev mailing list ([email protected]) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [email protected]
