问题
I am testing about function is first class citizen
in Swift. and I got in trouble. Check 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 if
line says: "'is' test is always true". But when I run the code, console print "ops" which means is
test is false. This confuses me. Why compiler says true when runtime says false?
来源:https://stackoverflow.com/questions/36173726/swift-use-is-for-function-type-compiler-behavior-is-different-with-runtime