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 trialJoel Muro
2,884 PointsCreate an enum called Speed with the following member values: Slow, Medium, and Fast. how to write this code?
this is the code i used.
enum Speed { class Slow, Medium, Fast }
what is wrong with my code and what is the correct way please.
2 Answers
Richard Lu
20,185 PointsHi Joel,
Your enum is saying that each of these values are classes, but that's invalid in Swift. Here's the valid way of defining an enum.
enum Speed {
case slow
case medium
case fast
}
or for short
enum Speed {
case slow, medium, fast
}
Hope I've helped. Happy Coding! :)
Chris Ward
12,129 PointsWhat weird syntax. In C, it's just enum Speed { Slow, Medium, Fast } You don't really need switch/case statements; after all the & and >> operators are your friends. :-)