Now that you have a deeper understanding about layout and user interfaces, it's time to take a step back and take a look at the underlying code you have been writing to build the HelloContacts app. If you have prior experience with OOP, nothing we have done so far should have frightened you. You might not have seen protocols used in class declarations before, but apart from that, inheritance in Swift is pretty much the same as you might have seen before.
However, as you have been playing around with Swift and iOS development, you might have noticed two object types you have not seen before: structs and enums. These two object types are what we refer to as value types. What this means and why it matters is covered in this chapter.
You will learn what structs and enums are and how you can use them in your own applications. You will also learn how these object types compare to traditional classes and how to make a choice between using a class, an enum or a struct. First, we'll look into classes and how they manifest themselves throughout apps a bit more, so you have a better understanding of the situation as you've seen it being set up until now. The topics covered in this chapter are the following:
- Understanding classes, also known as reference types
- Value types and how they compare to reference types
- Improving your code with structs
- Containing information in enums
- How to choose between the types
At the end of this chapter, you'll be able to distinguish between different object types and you should be able to use them in your own apps. During this chapter, we'll use a Playground to experiment with code. You can check out the Playground for this chapter in the Git repository for this book or you can create a new Playground and follow along.