Challenges

1. Update the printCarInfo method to print the string “Car undefined: no make specified.” if just make is nil; “Car undefined: no model specified.” if just model is nil; and keep printing “Car undefined: no make or model specified.” if both are nil. You can create test car objects using variations of the call to initWithMake:model:year:fuelAmount: from Listing 2-5 for checking your code.

2. Create a subclass of Car called ElectricCar. Take some time to design what that class might look like: the instance variables, modifications to existing methods, and any unique methods. When you have done that, either implement or read on for some possible approaches.

There are a few ways you could design the class for an electric car. Part of ...

Get Learning iOS Development: A Hands-on Guide to the Fundamentals of iOS Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.