Is there any way I can test if a method exists in Objective-C?
I\'m trying to add a guard to see if my object has the method before calling it.
You're looking for respondsToSelector:-
if ([foo respondsToSelector: @selector(bar)] {
[foo bar];
}
As Donal says the above tells you that foo can definitely handle receiving the bar selector. However, if foo's a proxy that forwards bar to some underlying object that will receive the bar message, then respondsToSelector: will tell you NO, even though the message will be forwarded to an object that responds to bar.