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

Bronze Challenge

Sometimes you write code that looks and feels right at the time, but in using it later you find that something is not quite right. This is the case with the extension you used to make Car conform to Vehicle.

When you made Car conform to the Vehicle protocol, you added a numberOfDoors computed property that always returns 4. This effectively makes numberOfDoors a constant on Car. As a consequence, the if/else condition in kind will always return .sedan. There is no other possibility due to how Car conforms to Vehicle.

Refactor Car to have a constant stored property named numberOfDoors. Note: This change will mean that you need to make other changes. Use the compiler errors to guide your solution.

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