I have a protocol that I defined like so:
protocol MyProtocol {
...
}
I also have a generic struct:
struct MyStruct <
A bit late but you can test if something responds to protocol with as ?
test:
if let currentVC = myViewController as? MyCustomProtocol {
// currentVC responds to the MyCustomProtocol protocol =]
}
EDIT: a bit shorter:
if let _ = self as? MyProtocol {
// match
}
And using a guard:
guard let _ = self as? MyProtocol else {
// doesn't match
return
}