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

Gold Challenge

Create a new Person class with two properties: name and age. For convenience, create an initializer that provides arguments for both of these properties.

Next, create two new instances of the Person class. Assign those instances to two constants named p1 and p2. Also create an array named people to hold these instances and then put them inside the array.

You will occasionally need to find the index of an instance of a custom type within an array. Call the index(of:) method on your array to do so. The argument takes the value of some element in the collection whose index you would like to find. Use the method to find the index of p1 inside of the people array.

You will get an error. Take some time to understand the ...

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