gpt4 book ai didi

ios - 如何使用 Typhoon 将属性注入(inject)基类

转载 作者:搜寻专家 更新时间:2023-11-01 07:23:51 25 4
gpt4 key购买 nike

我的类结构如下:

class BaseNetworkClient: NSObject {
var defaultParametersBuilder: DefaultParametersBuilder!
}

class NetworkClient: BaseNetworkClient {

}

class DefaultParametersBuilder: NSObject {

}

和台风大会

class CoreComponentsAssembly: TyphoonAssembly {
dynamic func baseNetworkClient() -> AnyObject {
return TyphoonDefinition.withClass(BaseNetworkClient.self) {
(definition) in
definition.scope = .ObjectGraph
definition.injectProperty(#selector(self.defaultParametersBuilder), with: self.defaultParametersBuilder())
}
}

dynamic func networkClient() -> AnyObject {
return TyphoonDefinition.withClass(NetworkClient.self) {
(definition) in
definition.scope = .ObjectGraph
}
}

dynamic func defaultParametersBuilder() -> AnyObject {
return TyphoonDefinition.withClass(DefaultParametersBuilder.self) {
(definition) in
definition.scope = .ObjectGraph
}
}
}

BaseNetworkClient 不注入(inject)任何类,但 NetworkClient 继承自它。问题是我无法向 BaseNetworkClient 注入(inject)任何属性。属性始终为零。怎么了?

最佳答案

项目 wiki 中描述了摘要和基本定义:https://github.com/appsquickly/Typhoon/wiki/Types-of-Injections#abstract-and-base-definitions

要继承注入(inject),您需要为定义设置父级:

definition.parent = self.baseNetworkClient()

程序集将发生如下变化:

dynamic func baseNetworkClient() -> AnyObject {
return TyphoonDefinition.withClass(BaseNetworkClient.self) {
(definition) in
definition.injectProperty(#selector(self.defaultParametersBuilder), with: self.defaultParametersBuilder())
}
}

dynamic func networkClient() -> AnyObject {
return TyphoonDefinition.withClass(NetworkClient.self) {
(definition) in
definition.parent = self.baseNetworkClient()
definition.scope = .ObjectGraph
}
}

关于ios - 如何使用 Typhoon 将属性注入(inject)基类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37249141/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com