Objective-C: preferred way to retrieve the superclass of a Class instance

MKroehnert picture MKroehnert · Aug 22, 2011 · Viewed 8.5k times · Source

I am wondering which of the two following methods is the correct or preferred one to retrieve the superclass of a Class variable:

  1. Class getSuperclass(Class cls) { return [cls superclass]; }

  2. Class getSuperclass(Class cls) { return class_getSuperclass(cls); }

Answer

Ben Zotto picture Ben Zotto · Aug 22, 2011

Well, the docs on class_getSuperclass() say this:

You should usually use NSObject‘s superclass method instead of this function

So, I'd go with door #1.