objective-cobjective-c-runtime

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


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); }


Solution

  • 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.