Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS Protocols in Swift Protocol Basics Protocols With Methods

Getting this to take value of enum Color as argument

So i am doing this challenge and have tried running this with a switch statement i thought was right and then this maybe right if else. What im a little confused on is how to take the value of color as an argument. The wording on this is tripping me up

protocols.swift
// Declare protocol here
protocol ColorSwitchable {
func switchColor (_ color) _> String
if bannanas = Color.rgb(23, 23, 23, 23)
print("bum") else print ("cool")


}


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)
  }
}
Nick Frozz
Nick Frozz
31,289 Points

Part 1/2 of this challenge is asking us to create a protocol named ColorSwitchable; You got it:

protocol ColorSwitchable {
}

Then it requires a func named "switchColor" with an omitted external argument "_", argument named "color" that has a value of "Color" inside of it, so you almost got it but forgot about a value. After 2nd step we're getting:

protocol ColorSwitchable {

func switchColor(_ color: Color)

}

Part 2/2. Asking us to adopt the ColorSwitchable protocol. To conform the protocol we need to use EVERY method and argument that our protocol has. In our case, it's a single function "switchColor". (function always goes before init.) :

class WifiLamp: ColorSwitchable {

let state: LightState

var color: Color

func switchColor(_ color: Color) {

self.color = color    //here we are simply setting a color to the new one.

}

init() {

self.state = .on
self.color = .rgb(0,0,0,0)

}
}