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

Brent Caswell
Brent Caswell
5,343 Points

Challenge help

Hey, I'm trying to complete the custom initializer code challenge. I think I'm having issues understanding how exactly I need to structure the description within the code. I've tried a few different ways, but I always seem to get an error. The latest error is that I need to use string concatenation for the description, but I think I'm already doing that. Any and all help is appreciated!

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

    let description = "red: \(red), green: \(green), blue: \(blue), alpha: \(alpha)"

2 Answers

Magnus Hållberg
Magnus Hållberg
17,232 Points

Its almost correct. You are declaring the same constant (description) twice in the same scope, that will give you an error. The only thing you need to do to pass is to move the second "description" constant in to the init method, then you delete the "let" so it referees to where you initially declared it. Also, you should not give the constants values inside the init, they should be "connected" to the init inputs. So that they get there values when you for example declare and initialize the RGBColors struct in a constant. Good luck.

Brent Caswell
Brent Caswell
5,343 Points

Thank you! This was really helpful.