I have this code:
if([annotation respondsToSelector:@selector(tag)]){
disclosureButton.tag = [annotation tag];
}
and I get the warning:
‘-tag’ not found in protocol
Fair enough, but I’ve created a new object with the protocol that has a synthesized int tag variable.
EDIT: found why the app was crashing – not this line. Now I just get a warning and the app works fine.
Thanks
Tom
The warning is generated because for the static type of
annotation,MKAnnotation, there is no method-tag. As you already checked wether the dynamic type responds to the selector you can ignore the warning in this case.To get rid of the warning:
If you expect a certain class you can test for it instead:
For a protocol:
Or if both do not apply use a specific protocol to suppress the warning (useful e.g. with rapidly changing Apple APIs):