上QQ阅读APP看书,第一时间看更新
Type annotation
In Swift, it is possible to annotate types, or in other words, explicitly specify the type of a variable or expression. Let's look at the following example:
let pi: Double = 3.14159
let piAndPhi: (Double, Double) = (3.14159, 1.618)
func ourFunction(a: Int) { /* ... */ }
In this example, we define a constant (pi) annotated as Double, a tuple named piAndPhi annotated as (Double, Double), and a parameter of ourFunction as Int.