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
As you can see this part of swift is unimplemented. (Xcode 6.3 beta 4)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With