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

Silver Challenge

Make a new type called Mayor. It should be a struct. The Town type should have a property called mayor that holds an instance of the Mayor type.

Have your town inform the mayor every time the property for population changes. If the town’s population decreases, have the instance of the Mayor log this statement to the console: I'm deeply saddened to hear about this latest tragedy. I promise that my office is looking into the nature of this rash of violence. If the population increases, then the mayor should do nothing.

(Hint: You should define a new instance method on the Mayor type to complete this challenge.)

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