If you use Cocoa Bindings and have an array of
NSString
s where one entry controls a check box in
your user interface, you need to provide a Value Transformer in Interface Builder.
I couldn't find one, so I wrote one. The core are two methods:
- (id)transformedValue:(id)value
{
if(value
&& [[NSString stringWithString:value]
isEqualToString:@"1"]) {
return [NSNumber numberWithBool:YES];
} else {
return [NSNumber numberWithBool:NO];
}
}
- (id)reverseTransformedValue:(id)value
{
if([value boolValue] == YES) {
return [NSString stringWithString:@"1"];
} else {
return [NSString stringWithString:@"0"];
}
}
They convert an NSString
to a BOOL
and
vice versa. This is not exactly true, as these functions work …