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!

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 Swift 2.0 Protocols Swift 2.0 Protocols Protocols With Methods

Where am i going wrong here?? Lost on part 2

my code is not compiling but im not sure where im going wrong

// 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)
var changedWifiLight = WifiLamp(state: .On, color: .RGB(20.0, 30.0, 20.0, 1.0))

1 Answer

Task 2 isn't looking for you to instantiate any variables. Pasan want's you to have the WifiLamp conform to the ColorSwitchable protocol.


protocol FooBar {
    func someMethod() -> String

class SomeClass: FooBar {}

Once the class is correctly attempting to conform to the protocol as I have shown. You must then implement any and all methods/variables declared in the protocol. So again as an example, my FooBar protocol has a single method called someMethod that returns a string. An implementation could look like this:

class SomeClass: FooBar {
    func someMethod() -> String {
        return "Hello World!"

Pasan is also looking for you to set the color of the lamp to self.color to the new color being passed into the method switchColor:

self.color = color