Reputation: 406
Following is the problem, that i cannot invoke class methods if the type is protocol.type. Is there an alternative pattern that could achieve this.
Real scenario is that i have arr: [SomeProtocol.Type] and i want to perform let strings: [String] = arr.map { $0.str }
protocol SomeProtocol: class {
static var str: String { get }
static func value() -> Int
}
class SomeClass: SomeProtocol {
static var str: String = "SomeClass"
static func value() -> Int {
return 1
}
}
let protocolType: SomeProtocol.Type = SomeClass.self
println(protocolType.str) // compile error
println(protocolType.value()) // compile error
Upvotes: 5
Views: 330
Reputation: 15464
As you can see this part of swift is unimplemented. (Xcode 6.3 beta 4)
Upvotes: 2