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 ...
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