FLEXGlobalsEntry.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. //
  2. // FLEXGlobalsEntry.h
  3. // FLEX
  4. //
  5. // Created by Javier Soto on 7/26/14.
  6. // Copyright (c) 2014 f. All rights reserved.
  7. //
  8. #import <UIKit/UIKit.h>
  9. @class FLEXGlobalsViewController;
  10. NS_ASSUME_NONNULL_BEGIN
  11. typedef NS_ENUM(NSUInteger, FLEXGlobalsRow) {
  12. FLEXGlobalsRowProcessInfo,
  13. FLEXGlobalsRowNetworkHistory,
  14. FLEXGlobalsRowSystemLog,
  15. FLEXGlobalsRowLiveObjects,
  16. FLEXGlobalsRowAddressInspector,
  17. FLEXGlobalsRowCookies,
  18. FLEXGlobalsRowBrowseRuntime,
  19. FLEXGlobalsRowAppKeychainItems,
  20. FLEXGlobalsRowAppDelegate,
  21. FLEXGlobalsRowRootViewController,
  22. FLEXGlobalsRowUserDefaults,
  23. FLEXGlobalsRowMainBundle,
  24. FLEXGlobalsRowBrowseBundle,
  25. FLEXGlobalsRowBrowseContainer,
  26. FLEXGlobalsRowApplication,
  27. FLEXGlobalsRowKeyWindow,
  28. FLEXGlobalsRowMainScreen,
  29. FLEXGlobalsRowCurrentDevice,
  30. FLEXGlobalsRowPasteboard,
  31. FLEXGlobalsRowCount
  32. };
  33. typedef NSString * _Nonnull (^FLEXGlobalsEntryNameFuture)(void);
  34. /// Simply return a view controller to be pushed on the navigation stack
  35. typedef UIViewController * _Nullable (^FLEXGlobalsTableViewControllerViewControllerFuture)(void);
  36. /// Do something like present an alert, then use the host
  37. /// view controller to present or push another view controller.
  38. typedef void (^FLEXGlobalsTableViewControllerRowAction)(FLEXGlobalsViewController * _Nonnull host);
  39. /// For view controllers to conform to to indicate they support being used
  40. /// in the globals table view controller. These methods help create concrete entries.
  41. ///
  42. /// Previously, the concrete entries relied on "futures" for the view controller and title.
  43. /// With this protocol, the conforming class itself can act as a future, since the methods
  44. /// will not be invoked until the title and view controller / row action are needed.
  45. ///
  46. /// Entries can implement \c globalsEntryViewController: to unconditionally provide a
  47. /// view controller, or \c globalsEntryRowAction: to conditionally provide one and
  48. /// perform some action (such as present an alert) if no view controller is available,
  49. /// or both if there is a mix of rows where some are guaranteed to work and some are not.
  50. /// Where both are implemented, \c globalsEntryRowAction: takes precedence; if it returns
  51. /// an action for the requested row, that will be used instead of \c globalsEntryViewController:
  52. @protocol FLEXGlobalsEntry <NSObject>
  53. + (NSString *)globalsEntryTitle:(FLEXGlobalsRow)row;
  54. // Must respond to at least one of the below.
  55. // globalsEntryRowAction: takes precedence if both are implemented.
  56. @optional
  57. + (nullable UIViewController *)globalsEntryViewController:(FLEXGlobalsRow)row;
  58. + (nullable FLEXGlobalsTableViewControllerRowAction)globalsEntryRowAction:(FLEXGlobalsRow)row;
  59. @end
  60. @interface FLEXGlobalsEntry : NSObject
  61. @property (nonatomic, readonly, nonnull) FLEXGlobalsEntryNameFuture entryNameFuture;
  62. @property (nonatomic, readonly, nullable) FLEXGlobalsTableViewControllerViewControllerFuture viewControllerFuture;
  63. @property (nonatomic, readonly, nullable) FLEXGlobalsTableViewControllerRowAction rowAction;
  64. + (instancetype)entryWithEntry:(Class<FLEXGlobalsEntry>)entry row:(FLEXGlobalsRow)row;
  65. + (instancetype)entryWithNameFuture:(FLEXGlobalsEntryNameFuture)nameFuture
  66. viewControllerFuture:(FLEXGlobalsTableViewControllerViewControllerFuture)viewControllerFuture;
  67. + (instancetype)entryWithNameFuture:(FLEXGlobalsEntryNameFuture)nameFuture
  68. action:(FLEXGlobalsTableViewControllerRowAction)rowSelectedAction;
  69. @end
  70. @interface NSObject (FLEXGlobalsEntry)
  71. /// @return The result of passing self to +[FLEXGlobalsEntry entryWithEntry:]
  72. /// if the class conforms to FLEXGlobalsEntry, else, nil.
  73. + (nullable FLEXGlobalsEntry *)flex_concreteGlobalsEntry:(FLEXGlobalsRow)row;
  74. @end
  75. NS_ASSUME_NONNULL_END