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

protocol challenge 2 - don't known what I'm doing wrong here

I thought i have already put in the method but the compiler keeps showing that the protocol ColorSwitchable needs a method as directed in the instructions???

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: Colorswitchable {
  let state: LightState
  var color: Color

  func switchColor(_color: Color) {
    self.color = color
    }

  init() {
    self.state = .on
    self.color = .rgb(0,0,0,0)
  }
}
douglas madson
douglas madson
Courses Plus Student 10,182 Points

In your switchColor function your external argument is "_color". The challenge wants the external argument omitted and the internal argument named 'color'. In order to omit an external argument for a function you would do something like this:

func someFunction(_ localArgument: Value)

Hope this helps!

2 Answers

douglas madson
PLUS
douglas madson
Courses Plus Student 10,182 Points

In your switchColor function your external argument is "_color". The challenge wants the external argument omitted and the internal argument named 'color'. In order to omit an external argument for a function you would do something like this:

func someFunction(_ localArgument: Value)

Hope this helps!

HI thank you for your answer but still can't seem to get code to work, if you are able to would you be able to give an example code for visual representation, it would be much appreciated Thanks

douglas madson
PLUS
douglas madson
Courses Plus Student 10,182 Points

So your switchColor function should look like this:

protocol ColorSwitchable { func switchColor(_ color: Color)

There is a space between the underscore character and "color".

Hope this helps