Trouble right at the start with this chapter

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!

When I moved on in the chapter, and created my own initializers, it all worked…so I only had trouble with the default initializers…weird.

I think the problem is that you had the mayor property in your file. This likely came from your solution to a previous challenge?

In any case, Town(population:numberOfStoplights:) is not the correct memberwise initializer because it does not provide parameters for all of the settable properties in your Town struct.

It is a good idea to make a separate copy of your projects to work on the challenges to help prevent these sorts of discrepancies.

Good advice. Thank you.

But we’re supposed to have had the mayor property in the file, as the instructions read “make a copy of the MonsterTown project from the last chapter”, as opposed to “two chapters ago”, right?

I’m getting the same error bthooper.

ETA: Fixed it:

var myTown = Town(mayor: Mayor(), population: 10_000, numberOfStoplights: 6)

The book advises that you create separate projects for your challenge solutions. The main text of each chapter (i.e., the text within the chapter that is separate from the challenges) does not assume that you completed the previous chapter’s challenges. In this case, and in some others, this means that subsequent chapters will have you write some error prone code if you have previous challenge solution code in them.