OK…for some reason, I’m already throwing errors and I just started chapter 17.
Here is my town structure declaration, from the previous chapter:
struct Town {
static let region = "South"
var mayor = Mayor()
var population = 5_422 {
didSet(oldPopulation) {
if population < oldPopulation {
print("The population has changed to \(population) from \(oldPopulation).")
mayor.mayorNotice()
}
}
}
var numberOfStoplights = 4
enum Size {
case small
case medium
case large
}
var townSize: Size {
get {
switch self.population {
case 0...10_000:
return Size.small
case 10_001...100_000:
return Size.medium
default: return Size.large
}
}
}
func printDescription() {
print("Population: \(population), number of stoplights: \(numberOfStoplights)")
}
mutating func changePopulation(by amount: Int) {
population += amount
}
}
I thought this was working, and when I run main, it builds and runs as I thought it would. However, if I change my main to use the memberwise initiliazers, I get a build error:
‘’'
var myTown = Town(population: 10_000, numberOfStoplights: 6)
That's the only change I made...adding the parameters. I get the error "Cannont invoke initializer for type "Town" with an argument list..."
What am I doing wrong?
TIA!