generics协议,types为Swift
我如何创建一个协议variables。 我的目标是一个协议将有一个genericstypes的函数,我正在使用正在访问Class
associatedtype
types,该函数将返回genericstypes。 下面的示例声明:
public protocol ComponentFactory { associatedtype T // A class and that class can be inherit from another so I need define generic type here func create() -> T }
我想为这个协议声明一个variables:
fileprivate var mComponentFactoryMap = Dictionary()
在这一行,我收到一个错误: Protocol 'ComponentFactory' can only be used as a generic constraint because it has Self or associated type requirements
我从Android看到,实际上从kotlin他们有一个interface
声明像:
private val mComponentFactoryMap = mutableMapOf<String, ComponentFactory>()
任何人都可以帮助我,我怎么可以从Swift声明?