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 Protocols in Swift Protocol Basics Protocols With Methods

nam pham
nam pham
12,270 Points

How to pass Protocol Challenge in Swift 3

After read direction, I added some code for Protocol "ColorSwitchable". I get error when recheck work. what do I miss anything?

protocols.swift
// Declare protocol here
protocol ColorSwitchable {
  func switchColor(color: Color)
}

enum LightState {
  case on, off
}

enum Color {
  case rgb(Double, Double, Double, Double)
  case hsb(Double, Double, Double, Double)
}

class WifiLamp {
  let state: LightState
  var color: Color

  init() {
    self.state = .on
    self.color = .rgb(0,0,0,0)
  }
}

Hi! I think that your missing the external argument label from your protocols method.

2 Answers

David Pike
David Pike
3,445 Points

try

func switchColor(_ color: Color) 

as in the challenge it says

make sure your external argument label is omitted by using an underscore

Devin Boddie
Devin Boddie
6,777 Points

I'm having the same problem even when I add the external argument label the code still won't pass. My code looks like the following:

protocol ColorSwitchable { func switchColor(_ color: Color) }

enum LightState { case On, Off }

enum Color { case RGB(Double, Double, Double, Double) case HSB(Double, Double, Double, Double) }

class WifiLamp { let state: LightState var color: Color

init() {
    self.state = .On
    self.color = .RGB(0,0,0,0)
}

}