I am trying to get rid of a PerformSelector warning, according to the solution described in this answer: performSelector may cause a leak because its selector is unknown
The line that is causing an issue is:
if ([self.target respondsToSelector:self.action]) {
[self.target performSelector:self.action withObject:self];
}
I have tried to solve it by changing the code to:
if ([self.target respondsToSelector:self.action]) {
SEL selector = self.action;
IMP imp = [self.target methodForSelector:selector];
void (*func)(id, SEL) = (void *)imp;
func(self.target, selector);
}
Although it no longer reports an issue, the app crashes when this method is invoked. How can I solve this issue? This question is not a duplicate because I have read the other answer and still am unable to solve the problem.