Copying
The concept of making copies has been lurking behind nearly every topic covered in this chapter. Developers often want to know if copying an instance yields a shallow or a deep copy. Swift does not provide any language-level support for making a deep copy, which means copies in Swift are shallow.
Let’s look at an example to get a better sense of what these concepts mean. Create a new instance of GreekGod and put that and the existing instances into an array.
Listing 18.14 Adding some gods
... let athena = GreekGod(name: "Athena") let gods = [athena, hecate, zeus]
You created a new Greek god named athena and added that instance, hecate, and zeus to a new array. You should see these gods contained within the new array ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access