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 Build a Weather App with Swift (Retired) Data Modeling With Structures Initializing a Struct

Delip Rao
Delip Rao
1,736 Points

Bummer about Bummer!

I'm writing the answer for this question: <pre> 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. </pre>

I think I have the correct answer (tested in a Playground):

struct Vehicle {

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

  init(numberOfWheels: Int = 4, numberOfDoors: Int = 4, color: String = "Blue") {
    self.numberOfWheels = numberOfWheels
    self.numberOfDoors = numberOfDoors
    self.color = color
  }
}

When I submit this I keep getting:

<pre> Bummer! You need to define a func called init inside of Vehicle. </pre>

<pre>


< Bummer! >


    \   ^__^
     \  (oo)\_______
        (__)\       )\/\
            ||----w |
            ||     ||

</pre>

1 Answer

Kevin Zoltany
Kevin Zoltany
16,282 Points

you messed up the init method.

struct Vehicle {

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

  init() {
    numberOfWheels = 4
    numberOfDoors = 4
    color = "Blue"
  }

}
Delip Rao
Delip Rao
1,736 Points

Why is it wrong if it successfully runs in XCode? I'm passing the expected values as defaults. If you still instantiate it with no args the object will be identical to the object created by your code.

let car = Vehicle()
Kevin Zoltany
Kevin Zoltany
16,282 Points

It's not wrong it just doesn't work for this code challenge. They want you to practice what you learned not what you didn't learn.