FLEXGlobalsTableViewControllerEntry.m 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. //
  2. // FLEXGlobalsTableViewControllerEntry.m
  3. // FLEX
  4. //
  5. // Created by Javier Soto on 7/26/14.
  6. // Copyright (c) 2014 f. All rights reserved.
  7. //
  8. #import "FLEXGlobalsTableViewControllerEntry.h"
  9. @implementation FLEXGlobalsTableViewControllerEntry
  10. + (instancetype)entryWithEntry:(Class<FLEXGlobalsTableViewControllerEntry>)cls
  11. {
  12. NSParameterAssert(cls);
  13. NSParameterAssert(
  14. [cls respondsToSelector:@selector(globalsEntryViewController)] ||
  15. [cls respondsToSelector:@selector(globalsEntryRowAction)]
  16. );
  17. FLEXGlobalsTableViewControllerEntry *entry = [self new];
  18. entry->_entryNameFuture = ^{ return [cls globalsEntryTitle]; };
  19. if ([cls respondsToSelector:@selector(globalsEntryViewController)]) {
  20. entry->_viewControllerFuture = ^{ return [cls globalsEntryViewController]; };
  21. } else {
  22. entry->_rowAction = [cls globalsEntryRowAction];
  23. }
  24. return entry;
  25. }
  26. + (instancetype)entryWithNameFuture:(FLEXGlobalsTableViewControllerEntryNameFuture)nameFuture
  27. viewControllerFuture:(FLEXGlobalsTableViewControllerViewControllerFuture)viewControllerFuture
  28. {
  29. NSParameterAssert(nameFuture);
  30. NSParameterAssert(viewControllerFuture);
  31. FLEXGlobalsTableViewControllerEntry *entry = [self new];
  32. entry->_entryNameFuture = [nameFuture copy];
  33. entry->_viewControllerFuture = [viewControllerFuture copy];
  34. return entry;
  35. }
  36. + (instancetype)entryWithNameFuture:(FLEXGlobalsTableViewControllerEntryNameFuture)nameFuture
  37. action:(FLEXGlobalsTableViewControllerRowAction)rowSelectedAction
  38. {
  39. NSParameterAssert(nameFuture);
  40. NSParameterAssert(rowSelectedAction);
  41. FLEXGlobalsTableViewControllerEntry *entry = [self new];
  42. entry->_entryNameFuture = [nameFuture copy];
  43. entry->_rowAction = [rowSelectedAction copy];
  44. return entry;
  45. }
  46. @end
  47. @implementation NSObject (FLEXGlobalsTableViewControllerEntry)
  48. + (FLEXGlobalsTableViewControllerEntry *)flex_concreteGlobalsEntry {
  49. if ([self conformsToProtocol:@protocol(FLEXGlobalsTableViewControllerEntry)]) {
  50. return [FLEXGlobalsTableViewControllerEntry entryWithEntry:self];
  51. }
  52. return nil;
  53. }
  54. @end