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

Amit Bareli
Amit Bareli
653 Points

can someone help me with the answer and explain? thanks in advance!

dont know where to start

structs.swift
struct RGBColor {
  let red: Double
  let green: Double
  let blue: Double
  let alpha: Double

  let description: String

  // Add your code below
}

1 Answer

Steven Jemmott
Steven Jemmott
8,109 Points

You will have to add an initializer to your struct. Naturally, structs will already have an initializer (If you created an instance of this struct it would give you something like this, given what you already have:

RGBColor(red: #redValue, green: #greenValue, blue: #blueValue, alpha: #alphaValue, description: #descriptionValue)

What you will need to do is create your own initializer that allows you to use the values (redValue, greenValue, blueVlaue, alphaValue) to create a custom string description.

Not trying to give the final answer but you will need to pass in the parameters you need to set the color values and alpha value so that you can create the description string possibly using String interpolation. All the best!