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

jesseborden
jesseborden
11,623 Points

Works in xCode but I get compilation error on objective

Not sure what the deal is. Tried in Chrome and Safari.

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

    let description: String

    init () {
        self.red = 1.00
        self.green = 2.00
        self.blue = 1.00
        self.alpha = 1.00
        self.description = "red: \(red), green: \(green), blue: \(blue), alpha: \(alpha)"
    }
}
Matt Skelton
Matt Skelton
4,548 Points

Hey Jesse,

So what you currently have will compile perfectly fine, although it's not quite right to satisfy the requirements of the challenge.

Currently, inside your init method we are assigning hard coded values to your variables. You want to change your init method to accept four parameters that will be used to populate your variables with data.

init(red: Double, green: Double, ...)
{
    self.red = red
    self.green = green
    ...
    ...
}

This is the sort of thing you need, though you'll need to your blue and alpha values in there too. Hope this sets you on the right track!

1 Answer

jesseborden
jesseborden
11,623 Points

Hey Matt,

Thanks for your answer! That was it!