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!

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 Object-Oriented Swift Complex Data Structures Custom Initializers

Khaled M
Khaled M
829 Points

I have no clue what to do. These quizzes always jump a step or two ahead of the videos and leave me clueless.

I don't know where to go from here. I tried a combination of different things for over an hour.

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 = 86.0
    self.green = 191.0
    self.blue = 131.0
    self.alpha = 1.0
    self.description = "red: \(red), green: \(green), blue: \(blue), alpha: \(alpha)"


1 Answer

Shay Paustovsky
Shay Paustovsky
969 Points

Hi There Khaled,

I will try to help you in this little problem although I'm not taking the iOS treehouse course.

First of all you do not need to include the description property inside the init() statement. Now let me explain how this works and hopefully if I'm wrong or missing something then I trust them to correct me.

when writing a custom initialiser for the structure "RGBColor" in the parenthesis you've done it correctly except the thing I've mentioned above. Going to the body of the "init" statement, when using the (.self) keyword followed by the name of the property, you refer to the property/data of the struct. In this case you give it an absolute value, but that is not the point of the challenge.

The purpose is when a fellow programmer will want to use this object, he'll have to use the initialiser method to assign initial values to the properties of the object, but if you assign them in the initialiser absolute values there is no point for the initialiser.

Instead of : self.red = 87.0 Write - self.red = red

(This means you're assigning the property 'red' of the object, the value that has been entered in the init method in this case 'red' the constant between the parenthesis.

Sorry if it's too long, and hopefully this has helped you!

Shay ;)