台风:将子类 属性 注入 withFactory:selector 的定义中:注入样式

Typhoon: Inject subclass property into definition from withFactory:selector: injection style

我正在使用 Typhoon 将依赖项注入 UIViewController 的子 class。我找到了 的潜在解决方案,它涉及使用 "factory" 注入方法对视图控制器进行实例化:

return TyphoonDefinition.withFactory(self.storyboard(), selector:"instantiateViewControllerWithIdentifier:", parameters: { (method) in
            method.injectParameterWith("camera-mode-controller")
        }, configuration: { (definition) in
            definition.injectProperty("cameraProvider", with: self.systemComponents.systemCameraProvider())
    })

然而,UIStoryboard 签名 func instantiateViewControllerWithIdentifier(identifier: String) -> UIViewController 表明这个工厂方法初始化器将创建一个 UIViewController,它没有我的子 class 的 属性 (dynamic var cameraProvider).因此,在运行时,属性 注入失败并显示 setter not found.

有没有办法说 "create definition with class: and factory: with method: and properties" 之类的东西,这样定义就知道它生成的 class 不是 UIViewController 但实际上,就我而言,一个CameraModeViewController: UIViewController?在我看到的 API 文档中挖掘,TyphoonDefinition.withParent:class:configuration: 可能与 withFactory:selector:parameters: 方法链接以产生这种效果?然而,我的尝试:

public dynamic func viewControllerFromID(id: String) -> AnyObject {
    return TyphoonDefinition.withFactory(self.storyboard(), selector: "instantiateViewControllerWithIdentifier:") {
        (method) in
        method.injectParameterWith(id)
    }
}

public dynamic func cameraModeViewController() -> AnyObject {
    return TyphoonDefinition.withParent(self.viewControllerFromID("camera-mode-controller"), `class`: CameraModeViewController.self) {
        (definition) in
        definition.injectProperty("cameraProvider", with: self.systemComponents.systemCameraProvider())
    }
}

产生错误:'You can't call a method on the runtime argument being passed in. It has to be passed in as-is' in -[TyphoonInjectionByRuntimeArgument forwardingTargetForSelector:] with selector argument "length"。有什么想法吗?

我自己解决了这个问题:由于版本控制问题,具有该标识符的故事板成员忘记了它的 UIViewController 子类分配,因此实际上不可转换,并且没有那个 属性.事实证明,Typhoon 可以很好地注入在视图控制器子类中声明的属性。