FLEXGlobalsEntry.h 3.9 KB

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