Get position in class hierarchy

Is there a way to get the number of ancestors for an instance of a class? For instance. a class of type UITouch would be level 2, since it inherits from NSObject.

+3
source share
1 answer
int level = 1;
Class cls = [UITouch class];
while (cls = [cls superclass])
  ++ level;
return level;
+6
source

Source: https://habr.com/ru/post/1741093/


All Articles