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

dhari alaradah
dhari alaradah
3,127 Points

help me to solve it please

i can not solve it help me please

structs.swift
struct RGBColor {
    let red: Double
    let green: Double
    let blue: Double
    let alpha: Double
    let description: String
  init (red: Double, green: Double, blue: Double, alpha: Double, description: String ) {
  self.red = red
  self.green = green
  self.blue = blue
  self.alpha = alpha
  self.description = "red: \(self.red) gren: \(self.green) blue: \(self.blue) alpha: \(self.alpha)"
  }
}
Digvijay Jaiswal
Digvijay Jaiswal
5,565 Points

Try separating all the values in self.description using "," eg: "red: (self.red), green: (self.green)........)

Also please check the spelling of your green: (self.green), its actually gren not green. let me know if that works

2 Answers

Hi Dhari,

You do not need to have the description: String inside your init() as you do not want to pass this value to the struct, but have the struct calculate this itself.

Also you need commas after each value and the correct spelling of green.

struct RGBColor {
    let red: Double
    let green: Double
    let blue: Double
    let alpha: Double
    let description: String

    init (red: Double, green: Double, blue: Double, alpha: Double) {
        self.red = red
        self.green = green
        self.blue = blue
        self.alpha = alpha
        self.description = "red: \(self.red), green: \(self.green), blue: \(self.blue), alpha: \(self.alpha)"
    }
}

Hope this helps

KB :octopus:

Ben Shockley
Ben Shockley
6,094 Points

So you've got a couple of issues here.

First: you should check your spelling and punctuation on the description string, those have to match pretty much exactly for the checker to pass it.

Second: What is the purpose of taking a description parameter in the init function? You should re-evaluate that and I think you'll find your mistake.