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

Code doesn't compile

I'm getting error even though I did what exactly is being asked. Can anybody help me with this please?

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

    let description: String

    // Add your code below
    init(r: Double, g: Double, b: Double, a: Double) {
        self.red = r
        self.green = g
        self.blue = b
        self.alpha = a

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

    }
}

1 Answer

Hi there,

I have come across this before and I agree that your code is correct. However, the challenge doesn't like the names of individual letters. If you change r to red etc. your code will compile.

I have flagged this with support before and got an answer that "it's just the way it is". I don't understand the technicalities of the tests behind the scenes.

So, change your r to red in both places (and for the others too) and your code will compile.

Steve.

Wow. Thank you so much. You saved so much time and energy!

No problem! Glad to help. :+1: