Swift - Constants with type


To declare the type of constant, use the colon operator : followed by the data type:


let diameter :Double = 8


The preceding statement declares diameter to be a Double constant.

You want to declare it explicitly because you are assigning an integer value to it.

If you don't do this, the compiler will assume it is an?integer constant.

Once a constant is created, you can no longer change its value:

let radius = 3.45
radius = 5.67   //---error---

Related Topic