I have an iPhone app in which I have a method in ClassB called:
-(void)login:(NSString *)url withDelegate:(id)delegate { }
this method is called from ClassA. I pass in the delegate parameter in order to pass a callback to ClassA when this method is finished:
if(delegate && [delegate respondsToSelector:@selector(parseLogin:)]) {
[delegate parseLogin:loginInfoDictionary];
}
However, I get a warning stating: -Instance method: parseLogin: not found
This is not surprising because I never cast the parameter delegate as any specific class. However, to keep this method as abstract as possible, I’d like to keep the datatype of delegate as id.
Is this possible????
I’m running iOS 5.1 (if it matters). I’d like to get rid of the warning if possible.
Many thanks!
Brett
A common way to handle this is create a protocol and have ClassA implement the protocol.
Then implement the protocol in ClassA
Then change your method to look like:
This will get rid of the warning and still be extensible.