Skip to content

Instantly share code, notes, and snippets.

@JadenGeller
Last active August 29, 2015 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JadenGeller/e1d2e89bdd9ac769e606 to your computer and use it in GitHub Desktop.
Save JadenGeller/e1d2e89bdd9ac769e606 to your computer and use it in GitHub Desktop.
Random Objective-C Class Returning Function
#import <objc/runtime.h>
Class randomClass(){
int numClasses = objc_getClassList(NULL, 0);
Class *classes = calloc(sizeof(Class), numClasses);
objc_getClassList(classes, numClasses);
Class randomClass = *(classes + arc4random_uniform(numClasses));
free(classes);
return randomClass;
}
id randomInstance(){
return [[randomClass() alloc]init];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment