FLEXGlobalsEntry.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 NSString *(^FLEXGlobalsEntryNameFuture)(void);
  12. /// Simply return a view controller to be pushed on the navigation stack
  13. typedef UIViewController *(^FLEXGlobalsTableViewControllerViewControllerFuture)(void);
  14. /// Do something like present an alert, then use the host
  15. /// view controller to present or push another view controller.
  16. typedef void (^FLEXGlobalsTableViewControllerRowAction)(FLEXGlobalsTableViewController *host);
  17. /// For view controllers to conform to to indicate they support being used
  18. /// in the globals table view controller. These methods help create concrete entries.
  19. ///
  20. /// Previously, the concrete entries relied on "futures" for the view controller and title.
  21. /// With this protocol, the conforming class itself can act as a future, since the methods
  22. /// will not be invoked until the title and view controller / row action are needed.
  23. @protocol FLEXGlobalsEntry <NSObject>
  24. + (NSString *)globalsEntryTitle;
  25. // Must respond to at least one of the below
  26. @optional
  27. + (instancetype)globalsEntryViewController;
  28. + (FLEXGlobalsTableViewControllerRowAction)globalsEntryRowAction;
  29. @end
  30. @interface FLEXGlobalsEntry : NSObject <FLEXPatternMatching>
  31. @property (nonatomic, readonly) FLEXGlobalsEntryNameFuture entryNameFuture;
  32. @property (nonatomic, readonly) FLEXGlobalsTableViewControllerViewControllerFuture viewControllerFuture;
  33. @property (nonatomic, readonly) FLEXGlobalsTableViewControllerRowAction rowAction;
  34. + (instancetype)entryWithEntry:(Class<FLEXGlobalsEntry>)entry;
  35. + (instancetype)entryWithNameFuture:(FLEXGlobalsEntryNameFuture)nameFuture viewControllerFuture:(FLEXGlobalsTableViewControllerViewControllerFuture)viewControllerFuture;
  36. + (instancetype)entryWithNameFuture:(FLEXGlobalsEntryNameFuture)nameFuture action:(FLEXGlobalsTableViewControllerRowAction)rowSelectedAction;
  37. @end
  38. @interface NSObject (FLEXGlobalsEntry)
  39. /// @return The result of passing self to +[FLEXGlobalsEntry entryWithEntry:]
  40. /// if the class conforms to FLEXGlobalsEntry, else, nil.
  41. + (FLEXGlobalsEntry *)flex_concreteGlobalsEntry;
  42. @end