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

Matthew Gibbs
Matthew Gibbs
3,859 Points

Is there an issue with string interpolation in the web-based editor?

I am stuck on this code challenge. I have my 'init' method here, which is compiling for me fine, locally in Xcode, but just says 'your code won't compile' on the web. It tells me there will be an error message but there is not.

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

  let description: String

  // Add your code below
  init(r: Double, g: Double, b: Double, a: Double){
        self.red = r
        self.green = g
        self.blue = b
        self.alpha = a

        self.description = "red: \(r), green: \(g), blue: \(b), alpha: \(a)"
    }
}

1 Answer

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,860 Points

Hey Matthew,

You've pretty much got it, you're just using the incorrect variable names. I'm not 100% sure if it is, in fact, a syntax error (I don't do much in iOS), but I know that using single character variable names is never a good idea. So, while the structure is correct, the code checker does not like the single characters.
If you just rename the variables to follow Swift Naming Conventions, the code will pass.

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)"
    }
}

Keep Coding! :) :dizzy: