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

.​.​.​
l​e​t​ ​a​t​h​e​n​a​ ​=​ ​G​r​e​e​k​G​o​d​(​n​a​m​e​:​ ​"​A​t​h​e​n​a​"​)l​e​t​ ​g​o​d​s​ ​=​ ​[​a​t​h​e​n​a​,​ ​h​e​c​a​t​e​,​ ​z​e​u​s​]

You created a new Greek god named athena and added that instance, hecate, and ...

Get Swift Programming: The Big Nerd Ranch Guide now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.