I'm trying to understand the directionality of Cocoa bindings. In particular, I've written this little program to demonstrate bindings, and I'm not sure why it outputs what it does. Here is the program:
@interface SimpleClass : NSObject
@property (retain) NSString *s;
@end
@implementation SimpleClass
@end
int main(int argc, char *argv[]) {
SimpleClass *simpleClass1 = [[SimpleClass alloc] init];
SimpleClass *simpleClass2 = [[SimpleClass alloc] init];
[simpleClass1 bind:@"s" toObject:simpleClass2 withKeyPath:@"s" options:nil];
//[simpleClass1 willChangeValueForKey:@"s"];
simpleClass1.s = @"Hello, World!";
//[simpleClass1 didChangeValueForKey:@"s"];
NSLog(@"%@", simpleClass1.s);
NSLog(@"%@", simpleClass2.s);
simpleClass2.s = @"Something else!";
NSLog(@"%@", simpleClass1.s);
NSLog(@"%@", simpleClass2.s);
return 0;
}
When I run this program, the output is:
Hello, World!
(null)
Something else!
Something else!
This leads me to believe that bindings are unidirectional. However, I've come across this and this that both seem to say that bindings should be bidirectional (though neither is very clear). Uncommenting the willChangeValueForKey and didChangeValueForKey lines doesn't affect the output.
Am I correct in my conclusion that bindings are unidirectional? Or is there some way to specify at binding creation time that it should be bidirectional?