FLEXObjcRuntimeViewController.m 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. //
  2. // FLEXObjcRuntimeViewController.m
  3. // FLEX
  4. //
  5. // Created by Tanner on 3/23/17.
  6. // Copyright © 2017 Tanner Bennett. All rights reserved.
  7. //
  8. #import "FLEXObjcRuntimeViewController.h"
  9. #import "TBKeyPathSearchController.h"
  10. #import "TBKeyPathToolbar.h"
  11. #import "UIGestureRecognizer+Blocks.h"
  12. #import "FLEXTableView.h"
  13. #import "FLEXObjectExplorerFactory.h"
  14. #import "FLEXAlert.h"
  15. @interface FLEXObjcRuntimeViewController () <TBKeyPathSearchControllerDelegate>
  16. @property (nonatomic, readonly ) TBKeyPathSearchController *keyPathController;
  17. @property (nonatomic, readonly ) UIView *promptView;
  18. // .@property (nonatomic, readonly) void (^callback)();
  19. @end
  20. @implementation FLEXObjcRuntimeViewController
  21. #pragma mark - Setup, view events
  22. - (void)viewDidLoad {
  23. [super viewDidLoad];
  24. self.title = @"📚 Runtime Browser";
  25. // Search bar stuff, must be first because this creates self.searchController
  26. self.showsSearchBar = YES;
  27. self.showSearchBarInitially = YES;
  28. // Using pinSearchBar on this screen causes a weird visual
  29. // thing on the next view controller that gets pushed.
  30. //
  31. // self.pinSearchBar = YES;
  32. self.searchController.searchBar.placeholder = @"UIKit*.UIView.-setFrame:";
  33. // Search controller stuff
  34. // key path controller automatically assigns itself as the delegate of the search bar
  35. // To avoid a retain cycle below, use local variables
  36. UISearchBar *searchBar = self.searchController.searchBar;
  37. TBKeyPathSearchController *keyPathController = [TBKeyPathSearchController delegate:self];
  38. _keyPathController = keyPathController;
  39. _keyPathController.toolbar = [TBKeyPathToolbar toolbarWithHandler:^(NSString *buttonTitle) {
  40. [keyPathController didPressButton:buttonTitle insertInto:searchBar];
  41. }];
  42. }
  43. - (void)viewWillAppear:(BOOL)animated {
  44. [super viewWillAppear:animated];
  45. [self.tableView deselectRowAtIndexPath:self.tableView.indexPathForSelectedRow animated:YES];
  46. }
  47. - (void)viewDidAppear:(BOOL)animated {
  48. [super viewDidAppear:animated];
  49. dispatch_async(dispatch_get_main_queue(), ^{
  50. // This doesn't work unless it's wrapped in this dispatch_async call
  51. [self.searchController.searchBar becomeFirstResponder];
  52. });
  53. }
  54. #pragma mark Delegate stuff
  55. - (void)didSelectImagePath:(NSString *)path shortName:(NSString *)shortName {
  56. [FLEXAlert makeAlert:^(FLEXAlert *make) {
  57. make.title(shortName);
  58. make.message(@"No NSBundle associated with this path:\n\n");
  59. make.message(path);
  60. make.button(@"Copy Path").handler(^(NSArray<NSString *> *strings) {
  61. UIPasteboard.generalPasteboard.string = path;
  62. });
  63. make.button(@"Dismiss").cancelStyle();
  64. } showFrom:self];
  65. }
  66. - (void)didSelectBundle:(NSBundle *)bundle {
  67. NSParameterAssert(bundle);
  68. FLEXObjectExplorerViewController *explorer = [FLEXObjectExplorerFactory explorerViewControllerForObject:bundle];
  69. [self.navigationController pushViewController:explorer animated:YES];
  70. }
  71. - (void)didSelectClass:(Class)cls {
  72. NSParameterAssert(cls);
  73. FLEXObjectExplorerViewController *explorer = [FLEXObjectExplorerFactory explorerViewControllerForObject:cls];
  74. [self.navigationController pushViewController:explorer animated:YES];
  75. }
  76. #pragma mark - FLEXGlobalsEntry
  77. + (NSString *)globalsEntryTitle:(FLEXGlobalsRow)row {
  78. return @"📚 Runtime Browser";
  79. }
  80. + (UIViewController *)globalsEntryViewController:(FLEXGlobalsRow)row {
  81. return [self new];
  82. }
  83. @end