Skip to content

Instantly share code, notes, and snippets.

@hcrub
Created November 7, 2013 17:11
Show Gist options
  • Save hcrub/7358176 to your computer and use it in GitHub Desktop.
Save hcrub/7358176 to your computer and use it in GitHub Desktop.
Objective C Runtime's objc_getClassList to obtain a list of registered class definitions
/**
* objc_getClassList
* Obtains the list of registered class definitions.
*
* int objc_getClassList(Class *buffer, int bufferLen)
*
* Parameters:
*
* buffer
* 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.
*
* bufferLen
* 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.
*/
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);
free(classes);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment