FLEXObjcRuntimeViewController.m 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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 *text, BOOL suggestion) {
  40. if (suggestion) {
  41. [keyPathController didSelectKeyPathOption:text];
  42. } else {
  43. [keyPathController didPressButton:text insertInto:searchBar];
  44. }
  45. } suggestions:keyPathController.suggestions];
  46. }
  47. - (void)viewWillAppear:(BOOL)animated {
  48. [super viewWillAppear:animated];
  49. [self.tableView deselectRowAtIndexPath:self.tableView.indexPathForSelectedRow animated:YES];
  50. }
  51. - (void)viewDidAppear:(BOOL)animated {
  52. [super viewDidAppear:animated];
  53. dispatch_async(dispatch_get_main_queue(), ^{
  54. // This doesn't work unless it's wrapped in this dispatch_async call
  55. [self.searchController.searchBar becomeFirstResponder];
  56. });
  57. }
  58. #pragma mark Delegate stuff
  59. - (void)didSelectImagePath:(NSString *)path shortName:(NSString *)shortName {
  60. [FLEXAlert makeAlert:^(FLEXAlert *make) {
  61. make.title(shortName);
  62. make.message(@"No NSBundle associated with this path:\n\n");
  63. make.message(path);
  64. make.button(@"Copy Path").handler(^(NSArray<NSString *> *strings) {
  65. UIPasteboard.generalPasteboard.string = path;
  66. });
  67. make.button(@"Dismiss").cancelStyle();
  68. } showFrom:self];
  69. }
  70. - (void)didSelectBundle:(NSBundle *)bundle {
  71. NSParameterAssert(bundle);
  72. FLEXObjectExplorerViewController *explorer = [FLEXObjectExplorerFactory explorerViewControllerForObject:bundle];
  73. [self.navigationController pushViewController:explorer animated:YES];
  74. }
  75. - (void)didSelectClass:(Class)cls {
  76. NSParameterAssert(cls);
  77. FLEXObjectExplorerViewController *explorer = [FLEXObjectExplorerFactory explorerViewControllerForObject:cls];
  78. [self.navigationController pushViewController:explorer animated:YES];
  79. }
  80. #pragma mark - FLEXGlobalsEntry
  81. + (NSString *)globalsEntryTitle:(FLEXGlobalsRow)row {
  82. return @"📚 Runtime Browser";
  83. }
  84. + (UIViewController *)globalsEntryViewController:(FLEXGlobalsRow)row {
  85. return [self new];
  86. }
  87. @end