Why would the first call to a KVC setter have an NSTextField instance as the argument?

Posted by Stephen on Stack Overflow See other posts from Stack Overflow or by Stephen
Published on 2010-05-12T19:22:02Z Indexed on 2010/05/12 19:24 UTC
Read the original article Hit count: 292

Filed under:
|
|
|
|

If I have a NSTextField bound through an NSObjectController to a model object, I would expect the setter of the model object to be called with an NSString as the argument, but instead, I receive the instance of the control that I am bound too the first time I am called.

- (NSString *)property {
    NSLog(@"returning property");
    return property;
}

- (void)setProperty:(NSString *)string {
    NSLog(@"recieved %@", string)
}

- (id) init {
if (self = [super init]) {
    property = [[NSString alloc] initWithString:@"value"];
    }
    NSLog(@"property is %@",property");
    return self;
}

(The program doesn't run if you try anything in setProperty, because it tries to send NSString messages to string - which might be an NSTextField.)

Console Output:

2010-05-12 14:19:14.096 Trouble[13108:10b] property is enter value
2010-05-12 14:19:14.100 Trouble[13108:10b] recieved <NSTextField: 0x1025210>
2010-05-12 14:19:14.106 Trouble[13108:10b] returning property

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about cocoa