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 trialHeath Robertson
Courses Plus Student 2,757 PointsNeed Help | Custom Initialisers Code Challenge | Object Oriented Swift 2.0
What am I Missing?
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, description: String) {
self.red = red
self.green = green
self.blue = blue
self.alpha = alpha
2 Answers
Nathan Tallack
22,160 PointsHi Heath,
What we are doing here is taking the rgba values into the init function and computing the description from them. Take a look at your modified code below.
struct RGBColor {
let red: Double
let green: Double
let blue: Double
let alpha: Double
let description: String
// Not passing in description here, because we compute it within.
init(red: Double, green: Double, blue: Double, alpha: Double) {
self.red = red
self.green = green
self.blue = blue
self.alpha = alpha
// Computing description using interpolation of rgba values.
description = "red: \(red), green: \(green), blue: \(blue), alpha: \(alpha)"
}
}
I hope this helps clear it up for you. :)
Steven Deutsch
21,046 PointsHey Heath Robertson,
Let's clear up a few things here. First, you have to remove the description parameter from your init() method. You will initialize the value of description using string interpolation and the values for red, green, blue, and alpha that you passed into the init() method. The init() method has access to the description property in the RGB struct because it is within it's scope (the method is nested inside of the struct).
init(red: Double, green: Double, blue: Double, alpha: Double) {
self.red = red
self.green = green
self.blue = blue
self.alpha = alpha
description = "red: \(red), green: \(green), blue: \(blue), alpha: \(alpha)"
}
Hope this helps. I think I did a poor job of explaining but ultimately led you to the correct result.
Heath Robertson
Courses Plus Student 2,757 PointsHeath Robertson
Courses Plus Student 2,757 PointsThanks