FLEXGlobalsEntry.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. FLEXGlobalsRowURLSession,
  32. FLEXGlobalsRowURLCache,
  33. FLEXGlobalsRowNotificationCenter,
  34. FLEXGlobalsRowMenuController,
  35. FLEXGlobalsRowFileManager,
  36. FLEXGlobalsRowTimeZone,
  37. FLEXGlobalsRowLocale,
  38. FLEXGlobalsRowCalendar,
  39. FLEXGlobalsRowMainRunLoop,
  40. FLEXGlobalsRowMainThread,
  41. FLEXGlobalsRowOperationQueue,
  42. FLEXGlobalsRowCount
  43. };
  44. typedef NSString * _Nonnull (^FLEXGlobalsEntryNameFuture)(void);
  45. /// Simply return a view controller to be pushed on the navigation stack
  46. typedef UIViewController * _Nullable (^FLEXGlobalsTableViewControllerViewControllerFuture)(void);
  47. /// Do something like present an alert, then use the host
  48. /// view controller to present or push another view controller.
  49. typedef void (^FLEXGlobalsTableViewControllerRowAction)(FLEXGlobalsViewController * _Nonnull host);
  50. /// For view controllers to conform to to indicate they support being used
  51. /// in the globals table view controller. These methods help create concrete entries.
  52. ///
  53. /// Previously, the concrete entries relied on "futures" for the view controller and title.
  54. /// With this protocol, the conforming class itself can act as a future, since the methods
  55. /// will not be invoked until the title and view controller / row action are needed.
  56. ///
  57. /// Entries can implement \c globalsEntryViewController: to unconditionally provide a
  58. /// view controller, or \c globalsEntryRowAction: to conditionally provide one and
  59. /// perform some action (such as present an alert) if no view controller is available,
  60. /// or both if there is a mix of rows where some are guaranteed to work and some are not.
  61. /// Where both are implemented, \c globalsEntryRowAction: takes precedence; if it returns
  62. /// an action for the requested row, that will be used instead of \c globalsEntryViewController:
  63. @protocol FLEXGlobalsEntry <NSObject>
  64. + (NSString *)globalsEntryTitle:(FLEXGlobalsRow)row;
  65. // Must respond to at least one of the below.
  66. // globalsEntryRowAction: takes precedence if both are implemented.
  67. @optional
  68. + (nullable UIViewController *)globalsEntryViewController:(FLEXGlobalsRow)row;
  69. + (nullable FLEXGlobalsTableViewControllerRowAction)globalsEntryRowAction:(FLEXGlobalsRow)row;
  70. @end
  71. @interface FLEXGlobalsEntry : NSObject
  72. @property (nonatomic, readonly, nonnull) FLEXGlobalsEntryNameFuture entryNameFuture;
  73. @property (nonatomic, readonly, nullable) FLEXGlobalsTableViewControllerViewControllerFuture viewControllerFuture;
  74. @property (nonatomic, readonly, nullable) FLEXGlobalsTableViewControllerRowAction rowAction;
  75. + (instancetype)entryWithEntry:(Class<FLEXGlobalsEntry>)entry row:(FLEXGlobalsRow)row;
  76. + (instancetype)entryWithNameFuture:(FLEXGlobalsEntryNameFuture)nameFuture
  77. viewControllerFuture:(FLEXGlobalsTableViewControllerViewControllerFuture)viewControllerFuture;
  78. + (instancetype)entryWithNameFuture:(FLEXGlobalsEntryNameFuture)nameFuture
  79. action:(FLEXGlobalsTableViewControllerRowAction)rowSelectedAction;
  80. @end
  81. @interface NSObject (FLEXGlobalsEntry)
  82. /// @return The result of passing self to +[FLEXGlobalsEntry entryWithEntry:]
  83. /// if the class conforms to FLEXGlobalsEntry, else, nil.
  84. + (nullable FLEXGlobalsEntry *)flex_concreteGlobalsEntry:(FLEXGlobalsRow)row;
  85. @end
  86. NS_ASSUME_NONNULL_END