Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I find out if the superclass also implements the same method that my subclass implements?

I want to know if the superclass implements method A from my subclass, which also implements method A, so that I can safely call [super A] from my subclass without getting an exception.

NSObject's respondsToSelector: doesn't work in this case, since that will always return true (because my subclass implements the method in question). Any ideas?

like image 406
James Hu Avatar asked Nov 27 '11 23:11

James Hu


1 Answers

You can use the class method instancesRespondToSelector: to do this. So from the subclass you can call [[self superclass] instancesRespondToSelector:@selector(...)] to determine if the superclass implements the method you require.

like image 149
mattjgalloway Avatar answered Sep 28 '22 14:09

mattjgalloway