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

challenge question problems Not clear why this is not working.

struct RGBColor { let red: Double let green: Double let blue: Double let alpha: Double

let description: String

// Add your code below init () { red = 86.0 green = 191.0 blue = 131.0 alpha = 1.0 description = "red: (red), green: (green), blue: (blue), alpha: (alpha)" } }

1 Answer

Hi Louis,

Your init method isn't quite right.

1) You need to add the parameters to the initializer (in the parentheses after the keyword "init")

2) You don't want to hardcode values into the initializer (at least not for this example). Instead, you will be using the parameter arguments passed in when the function is called (this will be clearer when you see the code below).

Here is the code:

struct RGBColor {
  let red: Double
  let green: Double
  let blue: Double
  let alpha: Double

  let description: String

  // Add your code below
  init(red: Double, green: Double, blue: Double, alpha: Double) {
    self.red = red
    self.green = green
    self.blue = blue
    self.alpha = alpha

    self.description = "red: \(red), green: \(green), blue: \(blue), alpha: \(alpha)"
   }
}

Now if you want to create a RGBColor object (and print to see the description string), you can do this in Playgrounds:

let myRGBColor = RGBColor(red: 86.0, green: 191.0, blue: 131.0, alpha: 1.0)
print(myRGBColor.description)

Hope that helps.