I have a method as an NSString *. If it exists, I want to call it, and if not, do nothing.
SEL eventSelector = NSSelectorFromString(eventSelectorStr);
if ([delegate respondsToSelector:eventSelector]) {
[delegate performSelector:eventSelector];
[delegate adapterDidFinishAdRequest:self];
}
else {
// Does not implement selector
}
This code does not work, since NSSelectorFromString will register the string as a selector, so respondsToSelector:eventSelector will cause a crash because the selector is actually invalid.
Why do you say that that doesn’t work? This is the most common way to implement invoking optional delegate methods. I’ve never had an issue with that construct not working.