Skip to content

Instantly share code, notes, and snippets.

@johnjohndoe
Created November 19, 2012 16:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnjohndoe/4111613 to your computer and use it in GitHub Desktop.
Save johnjohndoe/4111613 to your computer and use it in GitHub Desktop.
How to bind two NSTextField instances to one NSString member
@implementation AppDelegate
@synthesize window = _window;
@synthesize textField1 = m_textField1;
@synthesize textField2 = m_textField2;
@synthesize foo = m_foo;
- (id)init {
self = [super init];
if (self) {
m_foo = @"Init";
}
return self;
}
- (void)awakeFromNib {
assert(m_textField1);
assert(m_textField2);
NSDictionary* textFieldBindingOptions = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:YES], NSValidatesImmediatelyBindingOption,
[NSNumber numberWithBool:YES], NSContinuouslyUpdatesValueBindingOption,
nil];
[m_textField1 bind:@"value" toObject:self withKeyPath:@"foo" options:textFieldBindingOptions];
[m_textField2 bind:@"value" toObject:self withKeyPath:@"foo" options:textFieldBindingOptions];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment