我正在尝试将泛型与协议混合在一起,我的xD非常困难
我在Android/Java项目中实现了某些架构,我正在尝试重写它以适应swift/iOS项目.但我发现了这个限制.
ProtocolA
protocol ProtocolA {
}
Run Code Online (Sandbox Code Playgroud)
ProtocolB
protocol ProtocolB : ProtocolA {
}
Run Code Online (Sandbox Code Playgroud)
ImplementProtocolA
class ImplementProtocolA <P : ProtocolA> {
let currentProtocol : P
init(currentProtocol : P) {
self.currentProtocol = currentProtocol
}
}
Run Code Online (Sandbox Code Playgroud)
ImplementProtocolB
class ImplementProtocolB : ImplementProtocolA<ProtocolB> {
}
Run Code Online (Sandbox Code Playgroud)
因此,当我尝试将ProtocolB设置为实现ProtocolA的具体类型时,我收到此错误:
不支持使用'ProtocolB'作为符合协议'ProtocolA'的具体类型
1这种"限制"有什么理由吗?
2是否有任何解决方法可以实现此功能?
3它会在某个时候得到支持吗?
- 更新 -
我认为同一问题的另一个变种是:
查看协议
protocol View {
}
protocol GetUserView : View {
func showProgress()
func hideProgress()
func showError(message:String)
func showUser(userDemo:UserDemo)
}
Run Code Online (Sandbox Code Playgroud)
演示者协议
protocol Presenter {
typealias V : …Run Code Online (Sandbox Code Playgroud)