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 Initializers and Self

Can't figure this one out

Hello,

Apparently, I can't complete the next challenge. I don't know why it won't accept my code. When I test it in a playground in X-Code it works just fine.

These are the requirements:

Your task is to write a custom initializer method for the object. Using the initializer assign values to the first four properties. Using the values assigned to those properties create a value for the description property that is a string representation of the color object.

For example, given the values 86.0 for red, 191.0 for green, 131.0 for blue and 1.0 for alpha, each of the stored properties should hold these values and the description property should look like this:

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

Does anybody know what the problem might be?

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 = red //86.0
        self.green = green //191.0
        self.blue =  blue //131.0
        self.alpha = alpha // 1.0
        self.description = ("red: \(red),green:\(green),blue:\(blue),alpha:\(alpha)")
    }

}

RGBColor.init(red: 86.0, green: 191.0, blue: 131.0, alpha: 1.0)

1 Answer

Michael Hulet
Michael Hulet
47,912 Points

Look closely at the format Treehouse wants your description to be in. Specifically, there's supposed to be a space after every comma and colon in the string, like this:

"red: \(red), green: \(green), blue: \(blue), alpha: \(alpha)"

Hello, Michael.

Thank you immensely for taking the time to answer.

It works. I guess that just goes to prove that I ought to be more meticulous when writing code. Thank you .