FLEXGlobalsTableViewControllerEntry.h 2.4 KB

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