Friday, May 28, 2010

'TheClassName' may not respond to '-methodName:forKey:withType'

// file.m
- (void)methodName:(id)value forKey:(NSString*)key {
[self methodName:value forKey:key withType:A_TYPE];
}

- (void)methodName:(id)value forKey:(NSString*)key withType:(TYPES)type {
....
}

The above lines will show a warning similar to 'TheClassName' may not respond to '-methodName:forkey:withType'. This is because of the order that the methods are written. When the compiler encounters the first method it flags it because the second method has not yet been defined. Reorder the methods to avoid this annoying warning.


Another reason this warning message might show is because the method actually is not defined or cannot be found in the interface file. I had the above method declared in a protocol, not the actual interface file. I imported the protocol, but forgot to tell the class to use the protocol ( i didn't say "@interface TheClassName <TheProtocolName> "). I found this out by doing a right-click -> Jump to Definition. And it gave me two options (one in the protocol and one in the class) instead of just going to the Protocol's declaration.

No comments:

Post a Comment