SHARE
TWEET

Untitled

a guest Sep 15th, 2019 85 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #import <objc/runtime.h>
  2.  
  3. NSArray *AllImageNames() {
  4.     unsigned int imageCount = 0;
  5.     const char **imageNames = objc_copyImageNames(&imageCount);
  6.     NSMutableArray<NSString *> *imageNameStrings = [[NSMutableArray alloc] initWithCapacity:imageCount];
  7.     if (imageNames!=NULL) {
  8.         for (unsigned int i = 0; i < imageCount; i++){
  9.             const char *imageName = imageNames[i];
  10.             NSLog(@"image name: %s", imageNames[i]);
  11.             [imageNameStrings addObject:[NSString stringWithUTF8String:imageName]];
  12.         }
  13.         free(imageNames);
  14.     }
  15.     NSLog(@"Total image count: %u", imageCount);
  16.     return [imageNameStrings sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
  17. }
  18.  
  19. NSArray *AllClassNamesForImage(const char *imageName) {
  20.     unsigned int classNamesCount = 0;
  21.     const char ** classNames = objc_copyClassNamesForImage(imageName, &classNamesCount);
  22.    
  23.     NSMutableArray<NSString *> *classNameStrings = [[NSMutableArray alloc] initWithCapacity:classNamesCount];
  24.     if (classNames != NULL) {
  25.         for (int i = 0; i < classNamesCount; i++) {
  26.             const char *className = classNames[i];
  27.             NSLog(@"class name: %s", classNames[i]);
  28.             [classNameStrings addObject:[NSString stringWithUTF8String:className]];
  29.         }
  30.         free(classNames);
  31.     }
  32.     NSLog(@"Total class count: %u", classNamesCount);
  33.     return [classNameStrings sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
  34. }
  35.  
  36. // eg:
  37. //    AllImageNames();
  38. //    AllClassNamesForImage(class_getImageName([self class]));
  39. //    AllClassNamesForImage([NSBundle mainBundle].executablePath.UTF8String);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top