O'Reilly logo

Swift Functional Programming - Second Edition by Dr. Fatih Nayebi

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required