swifttypestype-deduction

Swift: Determine the type of this constant


What is exactly the type of this const (val)?

let val = { (a: Int, b:Int)->Int in a + b }(1 , 2)

Isn't it (Int,Int) -> Int ?


Solution

  • It is just Int, because it takes only the final result, you call a function there that takes 2 Ints and return their adding result, which is going to be 3

    In order to determine the type of a variable in the future you could just hold option key on the keyboard and hover over the variable name