TyphoonOptionMatcher with conformsToProtocol

时间:2015-11-26 12:47:10

标签: ios objective-c dependency-injection typhoon

如果我可以使用matcher来选择基于协议的定义,那将是很好的,例如:

- (UIViewController *)viewControllerForViewModel:(id <IViewModel>)viewModel
{
    return [TyphoonDefinition withOption:viewModel matcher:^(TyphoonOptionMatcher *matcher)
    {
        [matcher conformsToProtocol:@protocol(ILoginViewModel) use:[self loginViewController]];
        [matcher conformsToProtocol:@protocol(IMainViewModel) use:[self mainScreenViewController]];
        [matcher defaultUse:[self emptyScreen]];
    }];
}

是否可以使用Typhoon现在拥有的或可能有一些解决方法?

谢谢。

编辑: 我已经为TyphoonOptionMatch和TyphoonOptionMatcher添加了一些conformsToProtocol选项,是否值得创建PR?

TyphoonOptionMatch

@property (nonatomic) Protocol *proto;
....
+ (id)matchWithConformsToProto:(Protocol *)proto injection:(id)injection;

TyphoonOptionMatcher

- (void)conformsToProto:(Protocol *)aProtocol use:(id)injection
...
- (TyphoonOptionMatch *)matchForValue:(id)value {
...
    BOOL isConformProto = (match.proto && [value conformsToProtocol:match.proto]);

1 个答案:

答案 0 :(得分:0)

此功能已在3.4.5 release

中出现
[matcher caseConformsToProtocol:@protocol(IMainViewModel) 
                            use:[self mainScreenViewController]];