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 2.0 Complex Data Structures Custom Initializers

Daniel Fagbuyi
Daniel Fagbuyi
3,238 Points

Im very confused on this task someone help please!

This is what i have so far, where did i go wrong?

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

    let description: String

    init(red: Double, green: Double , blue: Double , alpha: Double )
        self.green = 191.0
        self.blue = 131.0
        self.alpha = 1.0
        description = "red:\(self.red), green:\(self.green) , blue: \(self.blue), alpha\(self.alpha)"


}
}

1 Answer

Tobias Helmrich
Tobias Helmrich
31,602 Points

Hey Daniel,

firstly note that you're missing the opening curly brace of your init method. You also forgot to initialize the red stored property in the initializer method and make sure to assign the values you give the initializer method as arguments to the stored properties because right now you're hardcoding those values.

Lastly also make sure to write the string in description exactly like the example you can see in the challenge description, so make sure to set the colons correctly and take care of spaces as the challenges can be very picky about this.

This should work:

struct RGBColor {
    let red: Double
    let green: Double
    let blue: Double
    let alpha: Double

    let description: String

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

I hope that helps! :)

Daniel Fagbuyi
Daniel Fagbuyi
3,238 Points

Thanks alot! I understand!