【发布时间】:2015-05-16 22:39:33
【问题描述】:
我有一系列符合MyProtocol的structs。我需要这些结构的 types 数组(因为它们有一个在MyProtocol 中声明的静态方法,我需要能够访问它)。我尝试了各种各样的东西,但我无法让 Xcode 喜欢它。
另外,在这被标记为欺骗之前——我试过this,但我得到的只是:
//Foo and Bar are structs conforming to MyProtocol
let MyStructArray: Array<MyProtocol.self> = [Foo.self, Bar.self]
//Protocol 'MyProtocol' can only be used as a generic constant because it has Self or associated type requirements
【问题讨论】:
-
MyProtocol是你写的协议吗?当你想多态地调用它时,为什么你把它设为静态?