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 trialBob Clanfield
2,372 PointsThis seems to work fine in Xcode? Structs in Swift...
I tried var.rgbColor among other variations, Xcode prefers _ anyway nothing seems to be correct.
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: \(self.red), green: \(self.green), blue:\(self.blue), alpha:\(self.alpha)"
_ = RGBColor (red: 86.0, green: 191.0, blue: 131.0, alpha: 1.0)
}
}
2 Answers
Shade Wilson
9,002 PointsYour self.description
line seems correct to me. I tried it as well and couldn't pass the test, so this may be a problem with the test itself and not your code. Note though that you don't want the last line where you call _ = RGBColor
within the init method. If you wanted to create an instance, that would be something you do outside the struct.
Donald Zarraonandia
4,434 PointsThere is nothing wrong with the test you have two small typos.
First, Shade is right in order to create and instance you would do that outside the struct.
Second, you need to make it look exactly like the example in the answer. You are missing two spaces it should be:
self.description = "red: (self.red), green: (self.green), blue:\ (self.blue), alpha:\ (self.alpha)" notice the spaces after blue:\ and alpha:\
You have: self.description = "red: (self.red), green: (self.green), blue:(self.blue), alpha:(self.alpha)"