FLEXClassShortcuts.m 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. //
  2. // FLEXClassShortcuts.m
  3. // FLEX
  4. //
  5. // Created by Tanner Bennett on 11/22/19.
  6. // Copyright © 2020 FLEX Team. All rights reserved.
  7. //
  8. #import "FLEXClassShortcuts.h"
  9. #import "FLEXShortcut.h"
  10. #import "FLEXObjectExplorerFactory.h"
  11. #import "FLEXObjectListViewController.h"
  12. #import "NSObject+FLEX_Reflection.h"
  13. @interface FLEXClassShortcuts ()
  14. @property (nonatomic, readonly) Class cls;
  15. @end
  16. @implementation FLEXClassShortcuts
  17. + (instancetype)forObject:(Class)cls {
  18. // These additional rows will appear at the beginning of the shortcuts section.
  19. // The methods below are written in such a way that they will not interfere
  20. // with properties/etc being registered alongside these
  21. return [self forObject:cls additionalRows:@[
  22. [FLEXActionShortcut title:@"Find Live Instances" subtitle:nil
  23. viewer:^UIViewController *(id obj) {
  24. return [FLEXObjectListViewController
  25. instancesOfClassWithName:NSStringFromClass(obj)
  26. ];
  27. }
  28. accessoryType:^UITableViewCellAccessoryType(id obj) {
  29. return UITableViewCellAccessoryDisclosureIndicator;
  30. }
  31. ],
  32. [FLEXActionShortcut title:@"List Subclasses" subtitle:nil
  33. viewer:^UIViewController *(id obj) {
  34. NSString *name = NSStringFromClass(obj);
  35. return [FLEXObjectListViewController subclassesOfClassWithName:name];
  36. }
  37. accessoryType:^UITableViewCellAccessoryType(id view) {
  38. return UITableViewCellAccessoryDisclosureIndicator;
  39. }
  40. ],
  41. [FLEXActionShortcut title:@"Explore Bundle for Class"
  42. subtitle:^NSString *(id obj) {
  43. return [self shortNameForBundlePath:[NSBundle bundleForClass:obj].executablePath];
  44. }
  45. viewer:^UIViewController *(id obj) {
  46. NSBundle *bundle = [NSBundle bundleForClass:obj];
  47. return [FLEXObjectExplorerFactory explorerViewControllerForObject:bundle];
  48. }
  49. accessoryType:^UITableViewCellAccessoryType(id view) {
  50. return UITableViewCellAccessoryDisclosureIndicator;
  51. }
  52. ],
  53. ]];
  54. }
  55. + (NSString *)shortNameForBundlePath:(NSString *)imageName {
  56. NSArray<NSString *> *components = [imageName componentsSeparatedByString:@"/"];
  57. if (components.count >= 2) {
  58. return [NSString stringWithFormat:@"%@/%@",
  59. components[components.count - 2],
  60. components[components.count - 1]
  61. ];
  62. }
  63. return imageName.lastPathComponent;
  64. }
  65. @end