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 trialChristoph Hellmuth
11,604 PointsI declare everything here but there is still the error that I am not following the directions: protocol ColorSwitchable
I declare everything here but there is still the error that I am not following the directions: protocol ColorSwitchable { func switchColor (color:Color) }
2 Answers
Nathan Tallack
22,160 PointsSo in the first step you define the protocol. It will look something like this:
protocol ColorSwitchable {
func switchColor(color: Color)
}
In the second step you need to apply this protocol to your WiFiLamp class. You do that by popping it in after the Class name like this:
class WifiLamp: ColorSwitchable {
Now your class needs to have that function defined to comply with the protocol, so you will add the function in your class that will look like this:
func switchColor (color: Color) {
self.color = color
}
So you need to remember that the protocol defines WHAT is required, then when you apply that to something like a class you need to then implement what is required in that class to comply.
juzek
16,109 PointsThere is a missing space, I've just had the same issue. Compare: func switchColor(color: Color) func switchColor(color:Color)
Christoph Hellmuth
11,604 PointsChristoph Hellmuth
11,604 PointsThank you :) I still couldn't find what the error was, espacillialy that in my playground everything worked perfectly.