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

adfsda

afsdf

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, description: String) {
      self.red = 100.0
      self.green = 50.0
      self.blue = 139.0
      self.alpha = 5.0
      self.description = "red: 100.0, green: 50.0, blue: 139.0, alpha: 5.0"
    }

}

1 Answer

Steven Parker
Steven Parker
229,771 Points

Adfsda indeed! :smile: I was both sympathetic to your frustration and amused by its expression.

The structure of your constructor looks good, but I noticed these two issues:

  • you are setting your property values using the literal values from the example instead of the passed arguments
  • your description value is also a literal string instead of constructing it using the arguments

If you build your object using the passed arguments instead of the literal values you should be good. But if you're still stuck, here's how I did it:


:warning: SPOILER ALERT


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