FLEXGlobalsTableViewController.m 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. //
  2. // FLEXGlobalsTableViewController.m
  3. // Flipboard
  4. //
  5. // Created by Ryan Olson on 2014-05-03.
  6. // Copyright (c) 2014 Flipboard. All rights reserved.
  7. //
  8. #import "FLEXGlobalsTableViewController.h"
  9. #import "FLEXUtility.h"
  10. #import "FLEXLibrariesTableViewController.h"
  11. #import "FLEXClassesTableViewController.h"
  12. #import "FLEXObjectExplorerViewController.h"
  13. #import "FLEXObjectExplorerFactory.h"
  14. #import "FLEXLiveObjectsTableViewController.h"
  15. typedef NS_ENUM(NSUInteger, FLEXGlobalsRow) {
  16. FLEXGlobalsRowAppClasses,
  17. FLEXGlobalsRowSystemLibraries,
  18. FLEXGlobalsRowLiveObjects,
  19. FLEXGlobalsRowAppDelegate,
  20. FLEXGlobalsRowRootViewController,
  21. FLEXGlobalsRowUserDefaults,
  22. FLEXGlobalsRowApplication,
  23. FLEXGlobalsRowKeyWindow,
  24. FLEXGlobalsRowMainScreen,
  25. FLEXGlobalsRowCurrentDevice
  26. };
  27. @interface FLEXGlobalsTableViewController ()
  28. @property (nonatomic, strong) NSArray *rows;
  29. @end
  30. @implementation FLEXGlobalsTableViewController
  31. - (id)initWithStyle:(UITableViewStyle)style
  32. {
  33. // Force grouped style.
  34. self = [super initWithStyle:UITableViewStyleGrouped];
  35. if (self) {
  36. self.title = @"🌎 Global State";
  37. }
  38. return self;
  39. }
  40. - (BOOL)prefersStatusBarHidden
  41. {
  42. return YES;
  43. }
  44. - (void)viewDidLoad
  45. {
  46. [super viewDidLoad];
  47. self.rows = @[@(FLEXGlobalsRowLiveObjects),
  48. @(FLEXGlobalsRowSystemLibraries),
  49. @(FLEXGlobalsRowAppClasses),
  50. @(FLEXGlobalsRowAppDelegate),
  51. @(FLEXGlobalsRowRootViewController),
  52. @(FLEXGlobalsRowUserDefaults),
  53. @(FLEXGlobalsRowApplication),
  54. @(FLEXGlobalsRowKeyWindow),
  55. @(FLEXGlobalsRowMainScreen),
  56. @(FLEXGlobalsRowCurrentDevice)];
  57. self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(donePressed:)];
  58. }
  59. - (void)donePressed:(id)sender
  60. {
  61. [self.delegate globalsViewControllerDidFinish:self];
  62. }
  63. #pragma mark - Table Data Helpers
  64. - (FLEXGlobalsRow)rowTypeAtIndexPath:(NSIndexPath *)indexPath
  65. {
  66. return [[self.rows objectAtIndex:indexPath.row] unsignedIntegerValue];
  67. }
  68. - (NSString *)titleForRowType:(FLEXGlobalsRow)rowType
  69. {
  70. NSString *title = nil;
  71. switch (rowType) {
  72. case FLEXGlobalsRowAppClasses:
  73. title = [NSString stringWithFormat:@"📕 %@ Classes", [FLEXUtility applicationName]];
  74. break;
  75. case FLEXGlobalsRowSystemLibraries:
  76. title = @"📚 System Libraries";
  77. break;
  78. case FLEXGlobalsRowLiveObjects:
  79. title = @"💩 Heap Objects";
  80. break;
  81. case FLEXGlobalsRowAppDelegate:
  82. title = [NSString stringWithFormat:@"👉 %@", [[[UIApplication sharedApplication] delegate] class]];
  83. break;
  84. case FLEXGlobalsRowRootViewController:
  85. title = [NSString stringWithFormat:@"🌴 %@", [[self.applicationWindow rootViewController] class]];
  86. break;
  87. case FLEXGlobalsRowUserDefaults:
  88. title = @"🚶 +[NSUserDefaults standardUserDefaults]";
  89. break;
  90. case FLEXGlobalsRowApplication:
  91. title = @"💾 +[UIApplication sharedApplication]";
  92. break;
  93. case FLEXGlobalsRowKeyWindow:
  94. title = @"🔑 -[UIApplication keyWindow]";
  95. break;
  96. case FLEXGlobalsRowMainScreen:
  97. title = @"💻 +[UIScreen mainScreen]";
  98. break;
  99. case FLEXGlobalsRowCurrentDevice:
  100. title = @"📱 +[UIDevice currentDevice]";
  101. break;
  102. }
  103. return title;
  104. }
  105. - (UIViewController *)drillDownViewControllerForRowType:(FLEXGlobalsRow)rowType
  106. {
  107. UIViewController *viewController = nil;
  108. switch (rowType) {
  109. case FLEXGlobalsRowAppClasses: {
  110. FLEXClassesTableViewController *classesViewController = [[FLEXClassesTableViewController alloc] init];
  111. classesViewController.binaryImageName = [FLEXUtility applicationImageName];
  112. viewController = classesViewController;
  113. } break;
  114. case FLEXGlobalsRowSystemLibraries: {
  115. FLEXLibrariesTableViewController *librariesViewController = [[FLEXLibrariesTableViewController alloc] init];
  116. librariesViewController.title = [self titleForRowType:FLEXGlobalsRowSystemLibraries];
  117. viewController = librariesViewController;
  118. } break;
  119. case FLEXGlobalsRowLiveObjects: {
  120. viewController = [[FLEXLiveObjectsTableViewController alloc] init];
  121. } break;
  122. case FLEXGlobalsRowAppDelegate: {
  123. id <UIApplicationDelegate> appDelegate = [[UIApplication sharedApplication] delegate];
  124. viewController = [FLEXObjectExplorerFactory explorerViewControllerForObject:appDelegate];
  125. } break;
  126. case FLEXGlobalsRowRootViewController: {
  127. UIViewController *rootViewController = [self.applicationWindow rootViewController];
  128. viewController = [FLEXObjectExplorerFactory explorerViewControllerForObject:rootViewController];
  129. } break;
  130. case FLEXGlobalsRowUserDefaults: {
  131. NSUserDefaults *standardUserDefaults = [NSUserDefaults standardUserDefaults];
  132. viewController = [FLEXObjectExplorerFactory explorerViewControllerForObject:standardUserDefaults];
  133. } break;
  134. case FLEXGlobalsRowApplication: {
  135. UIApplication *sharedApplication = [UIApplication sharedApplication];
  136. viewController = [FLEXObjectExplorerFactory explorerViewControllerForObject:sharedApplication];
  137. } break;
  138. case FLEXGlobalsRowKeyWindow: {
  139. viewController = [FLEXObjectExplorerFactory explorerViewControllerForObject:self.applicationWindow];
  140. } break;
  141. case FLEXGlobalsRowMainScreen: {
  142. UIScreen *mainScreen = [UIScreen mainScreen];
  143. viewController = [FLEXObjectExplorerFactory explorerViewControllerForObject:mainScreen];
  144. } break;
  145. case FLEXGlobalsRowCurrentDevice: {
  146. UIDevice *currentDevice = [UIDevice currentDevice];
  147. viewController = [FLEXObjectExplorerFactory explorerViewControllerForObject:currentDevice];
  148. } break;
  149. }
  150. return viewController;
  151. }
  152. #pragma mark - Table View Data Source
  153. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  154. {
  155. return 1;
  156. }
  157. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  158. {
  159. return [self.rows count];
  160. }
  161. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  162. {
  163. static NSString *CellIdentifier = @"Cell";
  164. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  165. if (!cell) {
  166. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
  167. cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  168. cell.textLabel.font = [FLEXUtility defaultTableViewCellLabelFont];
  169. }
  170. FLEXGlobalsRow rowType = [self rowTypeAtIndexPath:indexPath];
  171. cell.textLabel.text = [self titleForRowType:rowType];
  172. return cell;
  173. }
  174. #pragma mark - Table View Delegate
  175. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  176. {
  177. FLEXGlobalsRow rowType = [self rowTypeAtIndexPath:indexPath];
  178. UIViewController *drillDownViewController = [self drillDownViewControllerForRowType:rowType];
  179. [self.navigationController pushViewController:drillDownViewController animated:YES];
  180. }
  181. @end