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

What is a memberwise initializer?

I looked up this error but the descriptions of it look like Egyptian to me. Any help? No idea what I am supposed to be doing here

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 = description


1 Answer

Because it's a struct you don't need to have an init() as you can set the values directly. This challenge is asking you to make sure you don't do that and you do use the init method.

You have used the init method though so that error message is pretty unhelpful. The actual problem is with your description variable.

Using the values assigned to those properties create a value for the description property that is a string representation of the color object.

"red: 86.0, green: 191.0, blue: 131.0, alpha: 1.0"

The description variable shouldn't be passed into the init function and should be generated using string interpolation with the values that have been passed in

Edit: as you asked, this is the definition apple gives for a memberwise initialiser

Memberwise Initializers for Structure Types

All structures have an automatically generated memberwise initializer, which you can use to initialize the member properties of new structure instances. Initial values for the properties of the new instance can be passed to the memberwise initializer by name:

let vga = Resolution(width: 640, height: 480)

Unlike structures, class instances don’t receive a default memberwise initializer. Initializers are described in more detail in Initialization.