在我们的应用程序中,我们重用了一个基本视图控制器,它为我们的应用程序中的视图提供了通用功能。它需要注入视图和视图模型。我在程序集中创建了一个类似于以下内容的定义:
- (BaseViewController *)baseViewControllerWith:(UIView *)view andViewModel:(ViewModel *)viewModel {
return [TyphoonDefinition withClass:[MLBaseViewController class] configuration:^(TyphoonDefinition *definition) {
[definition useInitializer:@selector(initWithView:viewModel:) parameters:^(TyphoonMethod *initializer) {
[initializer injectParameterWith:view];
[initializer injectParameterWith:viewModel];
}];
}];
这里的想法是将这个定义重用于所有不同的用途。我们可能会注入一个SignUpView和SignUpViewModel:
- (SignUpViewController *)signUpViewControllerWithViewModel:(ViewModel *)viewModel {
[self baseViewControllerWith:[self signUpView:viewModel] andViewModel:viewModel]
}
我得到了一个相当热闹的运行时异常:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Congratulations you've tried to do something über-funky with Typhoon %). You are the 3rd person EVER to receive this error message. Returning a definition that is the result of a nested runtime argument is not supported. Instead unroll the definition.'
*
我这样做的原因是因为我有很多使用baseViewController定义的定义,我希望能够重用它并注入不同的视图/视图模型而不必重写该定义到处。台风不支持这个吗?