| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- //
- // FLEXGlobalsEntry.m
- // FLEX
- //
- // Created by Javier Soto on 7/26/14.
- // Copyright (c) 2014 f. All rights reserved.
- //
- #import "FLEXGlobalsEntry.h"
- @implementation FLEXGlobalsEntry
- + (instancetype)entryWithEntry:(Class<FLEXGlobalsEntry>)cls row:(FLEXGlobalsRow)row
- {
- BOOL providesVCs = [cls respondsToSelector:@selector(globalsEntryViewController:)];
- BOOL providesActions = [cls respondsToSelector:@selector(globalsEntryRowAction:)];
- NSParameterAssert(cls);
- NSParameterAssert(providesVCs || providesActions);
- FLEXGlobalsEntry *entry = [self new];
- entry->_entryNameFuture = ^{ return [cls globalsEntryTitle:row]; };
- if (providesVCs) {
- id action = providesActions ? [cls globalsEntryRowAction:row] : nil;
- if (action) {
- entry->_rowAction = action;
- } else {
- entry->_viewControllerFuture = ^{ return [cls globalsEntryViewController:row]; };
- }
- } else {
- entry->_rowAction = [cls globalsEntryRowAction:row];
- }
- return entry;
- }
- + (instancetype)entryWithNameFuture:(FLEXGlobalsEntryNameFuture)nameFuture
- viewControllerFuture:(FLEXGlobalsTableViewControllerViewControllerFuture)viewControllerFuture
- {
- NSParameterAssert(nameFuture);
- NSParameterAssert(viewControllerFuture);
- FLEXGlobalsEntry *entry = [self new];
- entry->_entryNameFuture = [nameFuture copy];
- entry->_viewControllerFuture = [viewControllerFuture copy];
- return entry;
- }
- + (instancetype)entryWithNameFuture:(FLEXGlobalsEntryNameFuture)nameFuture
- action:(FLEXGlobalsTableViewControllerRowAction)rowSelectedAction
- {
- NSParameterAssert(nameFuture);
- NSParameterAssert(rowSelectedAction);
- FLEXGlobalsEntry *entry = [self new];
- entry->_entryNameFuture = [nameFuture copy];
- entry->_rowAction = [rowSelectedAction copy];
- return entry;
- }
- #pragma mark FLEXPatternMatching
- - (BOOL)matches:(NSString *)query
- {
- return [self.entryNameFuture() localizedCaseInsensitiveContainsString:query];
- }
- @end
- #pragma mark - flex_concreteGlobalsEntry
- @implementation NSObject (FLEXGlobalsEntry)
- + (FLEXGlobalsEntry *)flex_concreteGlobalsEntry:(FLEXGlobalsRow)row {
- if ([self conformsToProtocol:@protocol(FLEXGlobalsEntry)]) {
- return [FLEXGlobalsEntry entryWithEntry:self row:row];
- }
- return nil;
- }
- @end
|