How to call static method provided by protocol in Swift
This looks like a bug or a non-supported feature. I would expect that the following works:
if let gsType = contact.dynamicType as? GroupStatus.Type {
if gsType.isPrivate() {
// ...
}
}
However, it does not compile:
error: accessing members of protocol type value 'GroupStatus.Type' is unimplemented
It does compile with FamilyContact.Type
instead of GroupStatus.Type
. A similar problem is reported here:
- Swift 1.1 and 1.2: accessing members of protocol type value XXX.Type' is unimplemented
Making isPrivate()
an instance method instead of a class method is
the only workaround that I currently can think of, maybe someone comes
with a better solution ...
Update for Swift 2 / Xcode 7: As @Tankista noted below, this has been fixed. The above code compiles and works as expected in Xcode 7 beta 3.