To solve the Bronze Challenge, I modified my Town.swift
structure:
import Foundation
struct Town {
var population = 5_422
var numberOfStoplights = 4
func printDescription() {
print("Populations: \(population); number of stoplights: \(numberOfStoplights)")
}
mutating func changePopulation(by amount: Int) {
if population + amount > 0 {
population += amount
} else {
population = 0
}
}
}
Is there a more elegant way to write the changePopulation(by:)
method?