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

austin teshuba
austin teshuba
3,573 Points

What exactly is wrong with the following code to create a custom initializer in Swift?

The instructions dictate to create a custom initializer for the properties within the struct RGBcolor and then create values for the 4 properties and then finally create a string representation for the properties. I feel like I did that, the compiler is returning no errors, and I am having issues with this because I want to move on but I don't want to continue if I don't know what I'm doing

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

    let description: String

    // Add your code below
}
Tim Rach
seal-mask
.a{fill-rule:evenodd;}techdegree
Tim Rach
Full Stack JavaScript Techdegree Student 25,127 Points

This should get you through, rewatch the last video and you should get it. If not, keep asking ;)

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

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