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 trialBradley Maskell
8,858 PointsSwift Enums printSpeed Challenge
import UIKit
enum Speed {
case Slow(String)
case Medium(String)
case Fast(String)
}
func printSpeed (speed: Speed) -> String {
switch speed {
case .Slow(let slow):
println("Slow")
case .Medium(let medium):
println("Medium")
case .Fast(let Fast):
println("Fast")
default:
return "Unknown"
}
}
I've had no luck. Please help.
5 Answers
Adam Little
6,735 PointsHere is the answer! I had to do what Jennifer Jones said and use raw values instead of associated values. Thanks again, Jennifer.
enum Speed: String {
case Slow = "Slow"
case Medium = "Medium"
case Fast = "Fast"
}
func printSpeed (speed: Speed) -> String{
switch speed {
case Speed.Slow:
return Speed.Slow.rawValue
case Speed.Medium:
return Speed.Medium.rawValue
case Speed.Fast:
return Speed.Fast.rawValue
default:
return "Unknown"
}
}
jennifer jones
2,765 PointsThis challenge got me as well lol. Here's a hint which will allow you to get it straight away:
Use Raw Values instead of Associated Values
Adam Little
6,735 PointsThis was a huge help and I got the answer right. I'll post it now.
Bradley Maskell
8,858 PointsHi Jennifer Jones,
It's still not working for me.
enum Speed {
case Slow(String)
case Medium(String)
case Fast(String) }
func printSpeed (speed: Speed) -> String {
switch speed {
case .Slow(let slow):
return slow.rawValue
case .Medium(let medium):
return medium.rawValue
case .Fast(let fast):
return fast.rawValue
default:
return "Unknown" }
}
Adam Little
6,735 PointsLooks like you're not formatting the markdown properly.
Next time, use the name of the programming language "swift" after the three backticks.
David Galindo
Courses Plus Student 2,294 PointsOhh!!! This makes more sense now. I was having a hard time with this challenge.
Bradley Maskell
8,858 PointsThanks! I figured it out.
Adam Little
6,735 PointsSure thing!
jennifer jones
2,765 PointsNo problem. Glad I could help
jennifer jones
2,765 Pointsjennifer jones
2,765 PointsYou are very welcome!