Skip to content

Instantly share code, notes, and snippets.

@Code-Hex
Created August 25, 2022 16:13
Show Gist options
  • Save Code-Hex/e081738e08e92d768f676fea5e7daa4c to your computer and use it in GitHub Desktop.
Save Code-Hex/e081738e08e92d768f676fea5e7daa4c to your computer and use it in GitHub Desktop.
Objective-C class dumper
#import <objc/runtime.h>
void dumpClass(Class clz) {
unsigned int instanceMethodCount = 0;
printf("Found %d instance methods on '%s'\n", instanceMethodCount, class_getName(clz));
Method *instanceMethods = class_copyMethodList(clz, &instanceMethodCount);
for (unsigned int i = 0; i < instanceMethodCount; i++) {
Method method = instanceMethods[i];
printf("- %s, %s\n",
sel_getName(method_getName(method)),
method_getDescription(method)->types);
}
free(instanceMethods);
unsigned int classMethodCount = 0;
printf("Found %d class methods on '%s'\n", classMethodCount, class_getName(clz));
Method *classMethods = class_copyMethodList(object_getClass(clz), &classMethodCount);
for (unsigned int i = 0; i < classMethodCount; i++) {
Method method = classMethods[i];
printf("- %s, %s\n",
sel_getName(method_getName(method)),
method_getDescription(method)->types);
}
free(classMethods);
unsigned int propCount = 0;
printf("Found %d properties on '%s'\n", propCount, class_getName(clz));
objc_property_t *props = class_copyPropertyList(clz, &propCount);
for (unsigned int i = 0; i < propCount; i++) {
objc_property_t prop = props[i];
printf("- %s\n", property_getName(prop));
}
free(props);
unsigned int protocolCount = 0;
printf("Found %d protocol on '%s'\n", protocolCount, class_getName(clz));
Protocol **protocols = class_copyProtocolList(clz, &protocolCount);
for (unsigned int i = 0; i < protocolCount; i++) {
Protocol *protocol = protocols[i];
printf("- %s\n", protocol_getName(protocol));
}
free(protocols);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment