Class objects are great for encapsulating data and functionality within a unifying concept, such as a person, as they allow individual instances to be referenced. However, not everything is an object. We may need to represent data that is logically grouped together, but there isn't much more than that. It's not more than the sum of its parts; it is the sum of its parts.
For this, there are structs. Short for structures, structs can be found in many programming languages. Structs are value types, as opposed to classes, which are reference types, and, as such, behave differently when passed around. In this recipe, we will learn how structs work in Swift, and when and how to use them.
Getting ready
This recipe will build on top of the previous recipe, so open the playground you have used for the previous recipe. Don't worry if you didn't work through the previous recipe, as this one will contain all the code you need.
How to do it...
We have...