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

Get Swift Programming: The Big Nerd Ranch Guide 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.