Let's say I have a trivial class like this:
@interface ABPair : NSObject
@property id key;
@property id value;
- (void) printSize;
@end
@implementation ABPair
- (void) printSize {
NSLog(@"the size of your key is: %@", NSStringFromSize([self.key sizeWithAttributes: nil]));
}
@end
This compiles with no warnings (in Xcode 5), and runs successfully, and prints a reasonable value.
However, if I made this one change:
@property id<NSCopying> key;
then I get two compiler errors:
- ARC Semantic Issue: No known instance method for selector 'sizeWithAttributes:'
- Semantic Issue: Passing 'id' to parameter of incompatible type 'NSSize' (aka 'struct CGSize')
Why is the compiler able to identify the proper method (on NSString) when I provide no information at all about the type, but unable to identify the method when I say that the object must be of a protocol to which that class conforms?