Chapter 16, Silver Challenge Solution

I modified Town.swift and added a Mayor.swift structure to the project.

//
//  Town.swift
//  MonsterTown
//

import Foundation

struct Town {
    static let world = "Earth"
    let region = "Middle"
    var mayor = Mayor()
    var population = 5_422 {
        didSet(oldPopulation) {
            if population <= oldPopulation {
                print("The population has changed to \(population) from \(oldPopulation).")
                mayor.sendThoughtsAndPrayers()
            }
        }
    }
    var numberOfStoplights = 4
    
    enum Size {
        case small
        case medium
        case large
    }
    
    var townSize: Size {
        switch population {
        case 0...10_000:
            return Size.small
            
        case 10_001...100_000:
            return Size.medium
            
        default:
            return Size.large
            
        }
    }
    
    func printDescription() {
        print("Populations: \(population); number of stoplights: \(numberOfStoplights)")
    }
    
    mutating func changePopulation(by amount: Int) {
        population += amount
    }
}
//
//  Mayor.swift
//  MonsterTown
//

import Foundation

struct Mayor {
    func sendThoughtsAndPrayers() {
        print("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.")
    }
}