"Object-Oriented Objective-C" was retired on May 31, 2020.

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

"Bummer! Make sure you're not using the memberwise initializer provided by default" What am I doing wrong?

This exercise is confusing me. I'm supposed to create a custom initializer method that assigns values to the first four properties and places them into a description, but the code I've written isn't passing the test. How do I fix this?

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: Double) {
      self.red = red
      self.green = green
      self.blue = blue
      self.alpha = alpha

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

2 Answers

Michael Hulet
Michael Hulet
47,913 Points

To clarify a bit, I think what luke jones is trying to say is that your init method doesn't need to take in a description parameter, because you're generating that yourself inside the init based on the other parameters, so if you remove that from the parameter list of your init method, you should be good

luke jones
luke jones
8,915 Points

Yeah that :)

Knowing what you want to say while not knowing what to say is forever a nuisance in the world of programming.

Thanks Michael

luke jones
luke jones
8,915 Points

Very close. Remember, you are already initialising the description value and therefore do not need to call it inside your init method. You have already set the value of description as a String and do not need to rewrite description outside the scope of the class.