Say I have the following Objective-C class:
@interface Foo {
int someNumber;
NSString *someString;
}
and for reasons that I will not participate here, I want to use KVC to update in general terms the values ββfor these variables:
[f setValue:object forKey:@"someNumber"];
or
[f setValue:object forKey:@"someString"];`
If it objectis a string and I am updating the variable someNumber, it seems to me that I need to know how to use NSNumberFormatter to get the NSNumber, and then Cocoa will automatically convert this to int inside setValue:forKey:.
Is there a way to avoid this custom code and have Cocoa output the conversion to int from a string, or do I need to check this situation each time and handle it myself?
drewh source
share