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

I don't know what I'm doing wrong. It tells me to ensure I'm not using the memberwise initializer.

So I thought I figured this one out, but it stills says wrong. Can anyone help?

structs.swift
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

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

2 Answers

Heidi Puk Hermann
Heidi Puk Hermann
33,366 Points

Hi, you are very close!

The error is in the initializer, when you include the description. Since you are returning it as a string literal, you should not include it in the parentheses. The rest of your code is fine :)

You should call your initializer like this:

   init(red: Double, green: Double, blue: Double, alpha: Double) { 
      /* .Put your code here */ 
   }

Thank you, I eventually figured that out! I had also forgotten to create an instance and assign values. oop! :)