O'Reilly logo

Swift Programming: The Big Nerd Ranch Guide by John Gallagher, Matthew Mathias

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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.

To get a sense of what these concepts mean, let’s look at an example. Create a new instance of GreekGod and put that and the existing instances into an array.

Listing 18.13 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 listed ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required