class Tiger {}
func describe(_ obj: Any) -> String {
switch obj {
case let i as Int where i == 2:
return "two"
case is Tiger:
return "Tiger!"
case let s as String where s == "Error":
return "Error String"
case is Int:
return "Int type"
case let s as String:
return "string value '\(s)'"
default:
return "Unknown type"
}
}
print(describe(42))
//printed: Int type
print(describe(Tiger()))
//printed: Tiger!
print(describe("test"))
//printed: string value 'test'