I configure bindings like this:
@property (nonatomic, copy) NSString *name;
@property (nonatomic, strong) NSObjectController *controller;
...
self.controller = [[NSObjectController alloc] initWithContent:nil];
[self.controller bind:NSContentObjectBinding toObject:self
withKeyPath:@"name" options:nil];
[self.controller addObject:@"Hello"];
...
NSTextField *textField = [NSTextField textFieldWithString:nil];
[textField bind:NSValueBinding toObject:self.controller
withKeyPath:@"content" options:nil];
The text field shows the string “Hello” after launch, then I change it to “World” and hit Return. However, only the object controller’s content is updated:
[controller.content isEqualToString:@"World"]; // YES
[self.name isEqualToString:@"World"]; // NO — WHY?
[self.name isEqualToString:@"Hello"]; // YES
So how do I configure the NSObjectController
to update the local property that it is bound to?