I have a protocol defined:
protocol Usable {
func use()
}
and a class that conforms to that protocol
class Thing: Usabl
As metioned in the Swift doc, the is
operator is the guy you need for the job:
The is operator checks at runtime to see whether the expression is of the specified type. If so, it returns true; otherwise, it returns false.
The check must not be known to be true or false at compile time.
Therefore, the following test would normally be what you need:
if thing is Usable {
usableThing.use()
} else {
println("can't use that")
}
However, as the doc specifies, Swift can detect at compile time that the expression is always true and declares an error to help the developer.