【发布时间】:2016-07-25 18:19:14
【问题描述】:
我需要创建一个字典变量,其中我的值将是SomeOtherClass 类并符合SomeProtocol。这相当于 Objective-C 中的以下声明:
NSMutableDictionary<SomeClass *, SomeOtherClass<SomeProtocol> *> *someOtherBySome;
那么,是否有可能使用 Swift 以同样简单的方式做到这一点?
我需要它,因为我可以创建带有签名的func:
func someFunc<T: SomeOtherClass where T: SomeProtocol>(param: T, otherParam: String)
我想从Dictionary 获取param 参数的值,而不需要类型转换。
【问题讨论】:
标签: swift generics nsmutabledictionary swift-dictionary