IOS: getting all classes in a bundle or a downloaded application

I am trying to get a list of classes loaded into the application at runtime. I am not interested in ALL classes, only those that are loaded. I know how to get a list of all classes, but iterating through them to check if they are in the downloaded package leads to random crashes and seems like an overwhelming way to do this.

I saw links to NSLoadedClasses, but I can't find anything about it, and I'm not sure if this applies to iOS (vs Mac). What is the right way to get this? Again, I need this at runtime.

+4
source share
1 answer

Looks like I figured it out. If you need to do this, here's how to do it:

#import <objc/runtime.h> #import <dlfcn.h> #import <mach-o/ldsyms.h> unsigned int count; const char **classes; Dl_info info; dladdr(&_mh_execute_header, &info); classes = objc_copyClassNamesForImage(info.dli_fname, &count); for (int i = 0; i < count; i++) { NSLog(@"Class name: %s", classes[i]); Class class = NSClassFromString ([NSString stringWithCString:classes[i] encoding:NSUTF8StringEncoding]); // Do something with class } 
+5
source

All Articles