Okay, I have a feeling that you guys'll be able to quickly point out why I'm so confused about this, but I have a question as to why the following does NOT result in a compiler error or warning:
NSString * intValue = [ NSString stringWithFormat:@"int = %i", [ [ self.selectedObject valueForKey:name ] integerValue ] ];
selectedObject
is an NSObject
, and name
happens to be the name of a @property
of type int
.
What perplexes me is why the compiler is perfectly willing to assume that the return result of [ self.selectedObject valueForKey:name ]
is of type NSNumber *
(without typecasting it) in order to chain the message with a call to integerValue
.
Obviously, KVC wraps up non-object "number" types into NSNumber
, but there's no way for the compiler to know that -valueForKey:
will return an NSNumber *
in this particular case.
Why doesn't this result in a compiler warning along the lines of "id
may not respond to '-integerValue
'"?