在我們的應用程序中,我們正在重用基本視圖控制器,該應用程序爲視圖提供了常見的功能。它需要注入一個視圖和一個視圖模型。我創建了一個我們大會的定義類似以下內容:是否可以重複使用Typhoon中具有運行時參數的定義?
- (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定義,我希望能夠重用它,只需注入不同的視圖/視圖模型,而不必在任何地方重寫該定義。颱風不支持嗎?