FLEXGlobalsEntry.h 3.6 KB

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