FLEXClassExplorerViewController.m 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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 *)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 *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. - (BOOL)customSectionCanDrillIntoRowWithCookie:(id)rowCookie
  76. {
  77. return YES;
  78. }
  79. - (UIViewController *)customSectionDrillInViewControllerForRowCookie:(id)rowCookie
  80. {
  81. UIViewController *drillInViewController = nil;
  82. FLEXClassExplorerRow row = [rowCookie unsignedIntegerValue];
  83. switch (row) {
  84. case FLEXClassExplorerRowNew:
  85. drillInViewController = [[FLEXMethodCallingViewController alloc] initWithTarget:self.theClass method:class_getClassMethod(self.theClass, @selector(new))];
  86. break;
  87. case FLEXClassExplorerRowAlloc:
  88. drillInViewController = [[FLEXMethodCallingViewController alloc] initWithTarget:self.theClass method:class_getClassMethod(self.theClass, @selector(alloc))];
  89. break;
  90. case FLEXClassExplorerRowLiveInstances:
  91. drillInViewController = [FLEXInstancesTableViewController instancesTableViewControllerForClassName:NSStringFromClass(self.theClass)];
  92. break;
  93. }
  94. return drillInViewController;
  95. }
  96. - (BOOL)shouldShowDescription
  97. {
  98. // Redundant with our title.
  99. return NO;
  100. }
  101. - (BOOL)canCallInstanceMethods
  102. {
  103. return NO;
  104. }
  105. - (BOOL)canHaveInstanceState
  106. {
  107. return NO;
  108. }
  109. @end