FLEXGlobalsEntry.m 2.2 KB

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