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

John Coppa
John Coppa
878 Points

I'm not understanding why my custom initializer is not correct.

Can I get some help with this question?

structs.swift
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 = Double
        self.green = Double
        self.blue = Double
        self.alpha = Double

    }
}


myRGB.description  //red: 86.0, green: 191.0, blue: 131.0, alpha: 1.0

2 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! You've got a few errors here, but don't seem to be too major so I'm going to try first with some hints.

  • Your struct ends before your init begins. Check your closing curly brace on your struct
  • The initialization of your properties is incorrect. For instance you should have self.red = red
  • The initialization of the description is missing entirely from your init

The instructions state that the description should be initialized to something that looks like this:

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

This is just an example. Do not hard-code these values. My suggestion here is to use string interpolation to get the desired results.

Hope this helps, but let me know if you're still stuck! :sparkles:

Kenneth G.
PLUS
Kenneth G.
Courses Plus Student 1,171 Points

You have to add the code inside the struct curly brace

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 = Double
        self.green = Double
        self.blue = Double
        self.alpha = Double

        }
}