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

Gabriel Ducharme
Gabriel Ducharme
11,948 Points

Custom initializer method in swift.

Why do I keep getting the error message to create my own custom initializer in the test? Isn't it what I'm doing?

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, description: String) {
        self.red = r
        self.green = g
        self.blue = b
        self.alpha = a
        self.description = "red: \(r), green: \(g), blue: \(b), alpha \(a)"


1 Answer

As you don't use the description parameter for creating a value for the description property, it is not necessary to declare it within the list of initializer parameters. The signature of the initializer should probably look like this:

init(r: Double, g: Double, b: Double, a: Double) {
    // Your initialization code goes here...