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

Immutable variables

In the imperative programming style, values held in application variables whose contents never change are known as constants to differentiate them from variables that could be altered during execution. Examples might include a view's height and width or the value of Π to several decimal places.

Unlike programming languages such as Objective-C in which some types are mutable and some are not, Swift provides a way to create an immutable or mutable version of the same type. In Swift, we use the let and var keywords to create and store values:

  • The var keyword is used to create a variable that can be altered later, in other words, to create mutable variables
  • The let keyword is used to create a constant that cannot be altered ...

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