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 trialMatthew Sharikov
5,767 PointsSwift 3 - Custom Initializers
Can someone please help me out with this problem?
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 = 86.0
self.green = 191.0
self.blue = 131.0
self.alpha = 1.0
self.description = "red: \(red), green: \(green), blue: \(blue), alpha: \(alpha)"
}
var myRGB = RGBColor(red: 30.0, green: 100.0, blue: 41.0, alpha: 15.0)
2 Answers
Jason Anders
Treehouse Moderator 145,860 PointsYou're probably going to kick yourself for this one :)
Everything is correct, except you added the init outside the closing curly brace for the struct. Just move that closing curly brace to after your code (put the init inside the struct) and all is good. :)
Matthew Sharikov
5,767 PointsThank you Jason once again!
Akshay Jain
2,576 PointsAkshay Jain
2,576 PointsHello Jason, could you explain why the self.description = syntax works? I understand the string interpolation but why the ("red:) and not just ("(red))? sorry if the parenthesis make my question confusing, I just don't understand the purpose of red: etc. Matthew please let me know if you see this before Jason does lol...thank you!