Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get position in class hierarchy

Tags:

objective-c

Is the a way to get the number of ancestors for an instance of class? E.g. a class of type UITouch would be of level 2 as it inherits from NSObject.

like image 451
jean Avatar asked Dec 07 '25 06:12

jean


1 Answers

int level = 1;
Class cls = [UITouch class];
while (cls = [cls superclass])
  ++ level;
return level;
like image 165
kennytm Avatar answered Dec 08 '25 18:12

kennytm