1
在我的演示項目中,我取代了手工創建與工廠爲基礎創建一個視圖控制器的組件中,像這樣(如碧玉藍調證明這裏:https://stackoverflow.com/a/24227246/397898)工廠初始化與產生額外的屬性注入
// ApplicationAssembly
dynamic func mainStoryboard() -> AnyObject {
return TyphoonDefinition.withClass(TyphoonStoryboard.self) {
(definition) in
definition.useInitializer("storyboardWithName:factory:bundle:") {
(initializer) in
initializer.injectParameterWith("Main")
initializer.injectParameterWith(self)
initializer.injectParameterWith(NSBundle.mainBundle())
}
definition.scope = TyphoonScope.Singleton
}
}
// PersonListAssembly
dynamic func personListViewController() -> AnyObject {
return TyphoonDefinition.withFactory(self.applicationAssembly.mainStoryboard(), selector: "instantiateViewControllerWithIdentifier:", parameters: {
(factoryMethod) in
factoryMethod.injectParameterWith("PersonListViewController")
})
}
但視圖控制器仍然需要一些其他的依賴關係。這樣做時我怎樣才能注入這個propery?
實際上,我有兩個問題:所有IBOutlets都是零,當我嘗試使用這樣的視圖控制器。我錯過了什麼嗎?基於Jasper的響應
正確答案
dynamic func personListViewController() -> AnyObject {
return TyphoonDefinition.withClass(PersonListViewController.self) {
(definition) in
definition.factory = self.applicationAssembly.mainStoryboard()
definition.useInitializer("instantiateViewControllerWithIdentifier:", parameters: { (factoryMethod) in
factoryMethod.injectParameterWith("PersonListViewController")
})
definition.injectProperty("presenter", with: self.personListPresenter())
}
}
太好了,謝謝。我將更新我的問題文本以提供我現在使用的正確代碼。 – 2014-10-31 17:06:41