You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

127 lines
3.5 KiB

  1. //
  2. // FLEXClassExplorerViewController.m
  3. // Flipboard
  4. //
  5. // Created by Ryan Olson on 6/18/14.
  6. // Copyright (c) 2014 Flipboard. All rights reserved.
  7. //
  8. #import "FLEXClassExplorerViewController.h"
  9. #import "FLEXMethodCallingViewController.h"
  10. #import "FLEXInstancesTableViewController.h"
  11. typedef NS_ENUM(NSUInteger, FLEXClassExplorerRow) {
  12. FLEXClassExplorerRowNew,
  13. FLEXClassExplorerRowAlloc,
  14. FLEXClassExplorerRowLiveInstances
  15. };
  16. @interface FLEXClassExplorerViewController ()
  17. @property (nonatomic, readonly) Class theClass;
  18. @end
  19. @implementation FLEXClassExplorerViewController
  20. - (Class)theClass
  21. {
  22. Class theClass = Nil;
  23. if (class_isMetaClass(object_getClass(self.object))) {
  24. theClass = self.object;
  25. }
  26. return theClass;
  27. }
  28. #pragma mark - Superclass Overrides
  29. - (NSArray<NSNumber *> *)possibleExplorerSections
  30. {
  31. // Move class methods to between our custom section and the properties section since
  32. // we are more interested in the class sections than in the instance level sections.
  33. NSMutableArray<NSNumber *> *mutableSections = [[super possibleExplorerSections] mutableCopy];
  34. [mutableSections removeObject:@(FLEXObjectExplorerSectionClassMethods)];
  35. [mutableSections insertObject:@(FLEXObjectExplorerSectionClassMethods) atIndex:[mutableSections indexOfObject:@(FLEXObjectExplorerSectionProperties)]];
  36. return mutableSections;
  37. }
  38. - (NSString *)customSectionTitle
  39. {
  40. return @"Shortcuts";
  41. }
  42. - (NSArray *)customSectionRowCookies
  43. {
  44. NSMutableArray *cookies = [NSMutableArray array];
  45. if ([self.theClass respondsToSelector:@selector(new)]) {
  46. [cookies addObject:@(FLEXClassExplorerRowNew)];
  47. }
  48. if ([self.theClass respondsToSelector:@selector(alloc)]) {
  49. [cookies addObject:@(FLEXClassExplorerRowAlloc)];
  50. }
  51. [cookies addObject:@(FLEXClassExplorerRowLiveInstances)];
  52. return cookies;
  53. }
  54. - (NSString *)customSectionTitleForRowCookie:(id)rowCookie
  55. {
  56. NSString *title = nil;
  57. FLEXClassExplorerRow row = [rowCookie unsignedIntegerValue];
  58. switch (row) {
  59. case FLEXClassExplorerRowNew:
  60. title = @"+ (id)new";
  61. break;
  62. case FLEXClassExplorerRowAlloc:
  63. title = @"+ (id)alloc";
  64. break;
  65. case FLEXClassExplorerRowLiveInstances:
  66. title = @"Live Instances";
  67. break;
  68. }
  69. return title;
  70. }
  71. - (NSString *)customSectionSubtitleForRowCookie:(id)rowCookie
  72. {
  73. return nil;
  74. }
  75. - (UIViewController *)customSectionDrillInViewControllerForRowCookie:(id)rowCookie
  76. {
  77. UIViewController *drillInViewController = nil;
  78. FLEXClassExplorerRow row = [rowCookie unsignedIntegerValue];
  79. switch (row) {
  80. case FLEXClassExplorerRowNew:
  81. drillInViewController = [[FLEXMethodCallingViewController alloc] initWithTarget:self.theClass method:class_getClassMethod(self.theClass, @selector(new))];
  82. break;
  83. case FLEXClassExplorerRowAlloc:
  84. drillInViewController = [[FLEXMethodCallingViewController alloc] initWithTarget:self.theClass method:class_getClassMethod(self.theClass, @selector(alloc))];
  85. break;
  86. case FLEXClassExplorerRowLiveInstances:
  87. drillInViewController = [FLEXInstancesTableViewController instancesTableViewControllerForClassName:NSStringFromClass(self.theClass)];
  88. break;
  89. }
  90. return drillInViewController;
  91. }
  92. - (BOOL)shouldShowDescription
  93. {
  94. // Redundant with our title.
  95. return NO;
  96. }
  97. - (BOOL)canCallInstanceMethods
  98. {
  99. return NO;
  100. }
  101. - (BOOL)canHaveInstanceState
  102. {
  103. return NO;
  104. }
  105. @end