在我们的应用程序中,我们重用了一个基本视图控制器,它为我们的应用程序中的视图提供通用功能。它需要注入视图和视图模型。我在我们的程序集中创建了一个类似于以下内容的定义:
- (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 定义的定义,我希望能够重用它并注入不同的视图/视图模型,而不必到处重写该定义。台风不支持此功能吗?