Obtains the list of registered class definitions.


func objc_getClassList(_ buffer: AutoreleasingUnsafeMutablePointer<AnyClass>?, _ bufferCount: Int32) -> Int32



An array of Class values. On output, each Class value points to one class definition, up to either bufferLen or the total number of registered classes, whichever is less. You can pass NULL to obtain the total number of registered class definitions without actually retrieving any class definitions.


An integer value. Pass the number of pointers for which you have allocated space in buffer. On return, this function fills in only this number of elements. If this number is less than the number of registered classes, this function returns an arbitrary subset of the registered classes.

Return Value

An integer value indicating the total number of registered classes.


The Objective-C runtime library automatically registers all the classes defined in your source code. You can create class definitions at runtime and register them with the objc_addClass function.

Listing 1 demonstrates how to use this function to retrieve all the class definitions that have been registered with the Objective-C runtime in the current process.

Listing 1

Using objc_getClassList

int numClasses;
Class * classes = NULL;
classes = NULL;
numClasses = objc_getClassList(NULL, 0);
if (numClasses > 0 )
    classes = malloc(sizeof(Class) * numClasses);
    numClasses = objc_getClassList(classes, numClasses);

Special Considerations

You cannot assume that class objects you get from this function are classes that inherit from NSObject, so you cannot safely call any methods on such classes without detecting that the method is implemented first.

See Also

Obtaining Class Definitions

func objc_copyClassList(UnsafeMutablePointer<UInt32>?) -> AutoreleasingUnsafeMutablePointer<AnyClass>?

Creates and returns a list of pointers to all registered class definitions.

func objc_lookUpClass(UnsafePointer<Int8>) -> AnyClass?

Returns the class definition of a specified class.

func objc_getClass(UnsafePointer<Int8>) -> Any!

Returns the class definition of a specified class.

func objc_getRequiredClass(UnsafePointer<Int8>) -> AnyClass

Returns the class definition of a specified class.

func objc_getMetaClass(UnsafePointer<Int8>) -> Any!

Returns the metaclass definition of a specified class.