Created
January 13, 2018 00:22
-
-
Save jslegendre/9b7a5b4b27a6f6f57ba3c7e606d580a7 to your computer and use it in GitHub Desktop.
A function to quickly write a list of the instance variables of a class to the console.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void class_printIvars(Class cl) { | |
unsigned int ivarCount; | |
Ivar *ivars = class_copyIvarList(cl, &ivarCount); | |
printf("Ivars for %s: \n", class_getName(cl)); | |
for (int i = 0; i < ivarCount; i++) { | |
Ivar ivar = ivars[i]; | |
printf("%s : %s \n", | |
ivar_getName(ivar), | |
ivar_getTypeEncoding(ivar)); | |
} | |
free(ivars); | |
} | |
int main(int argc, const char * argv[]) { | |
@autoreleasepool { | |
Class bundle = objc_getClass("NSBundle"); | |
class_printIvars(bundle); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment