Skip to content

Instantly share code, notes, and snippets.

@jslegendre
Created January 13, 2018 00:22
Show Gist options
  • Save jslegendre/9b7a5b4b27a6f6f57ba3c7e606d580a7 to your computer and use it in GitHub Desktop.
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.
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