• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: bind:toObject:withKeyPath:options: Unidirectional or Bidirectional?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: bind:toObject:withKeyPath:options: Unidirectional or Bidirectional?


  • Subject: Re: bind:toObject:withKeyPath:options: Unidirectional or Bidirectional?
  • From: Keith Duncan <email@hidden>
  • Date: Sat, 30 Jan 2010 17:12:52 +0000

>> 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@hidden)

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:

This email sent to email@hidden

  • Follow-Ups:
    • Re: bind:toObject:withKeyPath:options: Unidirectional or Bidirectional?
      • From: Jerry Krinock <email@hidden>
References: 
 >bind:toObject:withKeyPath:options: Unidirectional or Bidirectional? (From: Jerry Krinock <email@hidden>)
 >Re: bind:toObject:withKeyPath:options: Unidirectional or Bidirectional? (From: Quincey Morris <email@hidden>)
 >Re: bind:toObject:withKeyPath:options: Unidirectional or Bidirectional? (From: Jerry Krinock <email@hidden>)

  • Prev by Date: Re: Returning a nil float?
  • Next by Date: Re: Tabbed windows
  • Previous by thread: Re: bind:toObject:withKeyPath:options: Unidirectional or Bidirectional?
  • Next by thread: Re: bind:toObject:withKeyPath:options: Unidirectional or Bidirectional?
  • Index(es):
    • Date
    • Thread