FLEXObjcRuntimeViewController.m 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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.pinSearchBar = YES;
  28. self.searchController.searchBar.placeholder = @"UIKit*.UIView.-setFrame:";
  29. // Search controller stuff
  30. // key path controller automatically assigns itself as the delegate of the search bar
  31. // To avoid a retain cycle below, use local variables
  32. UISearchBar *searchBar = self.searchController.searchBar;
  33. TBKeyPathSearchController *keyPathController = [TBKeyPathSearchController delegate:self];
  34. _keyPathController = keyPathController;
  35. _keyPathController.toolbar = [TBKeyPathToolbar toolbarWithHandler:^(NSString *buttonTitle) {
  36. [keyPathController didPressButton:buttonTitle insertInto:searchBar];
  37. }];
  38. }
  39. - (void)viewWillAppear:(BOOL)animated {
  40. [super viewWillAppear:animated];
  41. [self.tableView deselectRowAtIndexPath:self.tableView.indexPathForSelectedRow animated:YES];
  42. }
  43. - (void)viewDidAppear:(BOOL)animated {
  44. [super viewDidAppear:animated];
  45. dispatch_async(dispatch_get_main_queue(), ^{
  46. // This doesn't work unless it's wrapped in this dispatch_async call
  47. [self.searchController.searchBar becomeFirstResponder];
  48. });
  49. }
  50. #pragma mark Delegate stuff
  51. - (void)didSelectImagePath:(NSString *)path shortName:(NSString *)shortName {
  52. [FLEXAlert makeAlert:^(FLEXAlert *make) {
  53. make.title(shortName);
  54. make.message(@"No NSBundle associated with this path:\n\n");
  55. make.message(path);
  56. make.button(@"Copy Path").handler(^(NSArray<NSString *> *strings) {
  57. UIPasteboard.generalPasteboard.string = path;
  58. });
  59. make.button(@"Dismiss");
  60. } showFrom:self];
  61. }
  62. - (void)didSelectBundle:(NSBundle *)bundle {
  63. NSParameterAssert(bundle);
  64. FLEXObjectExplorerViewController *explorer = [FLEXObjectExplorerFactory explorerViewControllerForObject:bundle];
  65. [self.navigationController pushViewController:explorer animated:YES];
  66. }
  67. - (void)didSelectClass:(Class)cls {
  68. NSParameterAssert(cls);
  69. FLEXObjectExplorerViewController *explorer = [FLEXObjectExplorerFactory explorerViewControllerForObject:cls];
  70. [self.navigationController pushViewController:explorer animated:YES];
  71. }
  72. #pragma mark - FLEXGlobalsEntry
  73. + (NSString *)globalsEntryTitle:(FLEXGlobalsRow)row {
  74. return @"📚 Runtime Browser";
  75. }
  76. + (UIViewController *)globalsEntryViewController:(FLEXGlobalsRow)row {
  77. return [self new];
  78. }
  79. @end