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

Hello, Can someOne tell me what I am doing wrong!. Thank you

n the editor below, I've declared a class, WifiLamp, that represents an interface to one of those Internet of Things lamps. The class models state that determines whether the lamp is on or off and a color, represented by the Color enum. For the first step, declare a protocol named ColorSwitchable. The protocol has a single requirement: a method named switchColor that takes a value of Color as an argument. For the sake of this challenge, make sure your method parameter is named color.

protocols.swift
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)
  }
}

2 Answers

Chris Stromberg
PLUS
Chris Stromberg
Courses Plus Student 13,389 Points

The instruction ask you to omit the external parameter name. You need to use an _ to do this.

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

ohh I see! Thank you so much Chris Stromberg.