Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing members of protocol type doesn't work in Swift

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
like image 609
KSC Avatar asked Nov 01 '22 07:11

KSC


1 Answers

enter image description here

As you can see this part of swift is unimplemented. (Xcode 6.3 beta 4)

like image 82
mustafa Avatar answered Nov 05 '22 10:11

mustafa