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 trialDurus Mihai
2,660 PointsI don't know hot to continue this protocol task..
Can you help me in how to switch the color? thank you!
// Declare protocol here
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)->(){
return switch color{
case .RGB :
}
}
init() {
self.state = .On
self.color = .RGB(0,0,0,0)
}
}
protocol ColorSwitchable{
func switchColor(color: Color)->()
}
3 Answers
Chris Stromberg
Courses Plus Student 13,389 PointsDurus,
Your external parameter name is not used in this challenge so you need to use an underscore in your method signature.
Also we are changing the color of the WifiLamp by a color we pass into the function as a variable/parameter. So you would need to show this within the body of your function by setting the self.color to the color you pass in as a parameter.
Only this line of code would be placed within the body of the WifiLamp class.
func switchColor(_ color: Color) {
self.color = color
}
It may help you to check your code in an xcode playground and check for errors there so you don't have to ask for help on each challenge.
Also if you like the answers I am helping you with, you should mark them as best answer so I receive some credit for helping you. Good luck!
Florian Thompson
Courses Plus Student 18,609 PointsHi Durus,
you're off to a great start. It's mostly the return
statement that's on the wrong place.
here's how you switch color in your switchColor
method:
switch color {
case .RGB: ... do something
case .HSB: ... do something
}
Durus Mihai
2,660 Pointscan you be more explicitly, because i dont really get what should i write to change the values... and where should the return go?