I am testing function is first class citizenin Swift. and I had problems. Check out the code below:
let f: Int -> Int = { $0 }
if f is (Int -> Int?) { // compiler warning: 'is' test is always true
print("hello")
} else {
print("ops") // runtime: this line is executed
}
I got a compiler warning in the line if: "test is always true". But when I run the code, the console prints โopsโ, which means the test isis false. It bothers me. Why does the compiler say true when runtime says false?
source
share