O'Reilly logo

Learning Swift by Andrew J Wagner

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

Value types versus reference types

All variables and constants in Swift are stored in the computer's memory. In fact, unless you explicitly write data to the filesystem, everything you create goes in the memory. In Swift, there are two different categories of types. These two categories are value types and reference types. The only way that they differ is in the way they behave when they are assigned to new variables, passed into methods, or captured in closures. Essentially, they only differ when you try to assign a new variable or constant to the value of an existing variable or constant.

A value type is always copied when it is assigned somewhere new, while a reference type is not. Before we look at exactly what this means in more detail, let's ...

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