-
Book Overview & Buying
-
Table Of Contents
Mastering Swift 6 - Seventh Edition
By :
Structures are value types. When structures are passed within our application, we're actually passing copies of them rather than the original structures. This means that each part of our code receives its own copy of the structure, enabling it to make changes as necessary without impacting the original instance of the structure.
We are using structures for our examples here but enumerations are also value types and function in the same way.Classes are reference types; therefore, when we pass an instance of a class within our application, we are passing a reference to the original instance of the class. Any changes made to the instance of the class will persist.
It is very important to understand this difference between value types and reference types. We will discuss a very high-level view here but will provide additional details in Chapter 15, Memory Management.
To illustrate the difference between value types and reference types, let's examine...