Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

initializers

Heres the question "Let's assume we have a struct named Vehicle with a few stored properties as listed below. Let's create an initializer method and give the stored properties sensible initial values. We want to set the number of doors to 4, the number of wheels to 4 and the color to Blue."

This is what i put,

struct Vehicle {

  var numberOfWheels: Int
  var numberOfDoors: Int
  var color: String

init()

numberOfWheels [4]
numberOfDoors [4]
color [Blue]

}

1 Answer

your syntax is not correct. you need opening and closing brackets after init() and your code needs to go between them, and you need to assign the values using propertyName = value syntax. you only use brackets when working with arrrays and dictionaries.

struct Vehicle {

  var numberOfWheels: Int
  var numberOfDoors: Int
  var color: String

init() {

numberOfWheels = 4
numberOfDoors = 4 
color = "Blue"

}

}