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 trialMicah DeLaurentis
3,534 Pointsfixed data, so why list all cases
Since there are only 7 values, why do you have to list all the cases? Why not just sat, sun = weekend, and some key word like "else" or "otherwise"-- weekday.
2 Answers
faraz
Courses Plus Student 21,474 PointsYou can do that. See the following example:
func weekdayOrWeekend(day: Day) -> String {
switch day {
case .Saturday, .Sunday: return "Weekend"
default: return "Weekday"
}
}
and call it like this:
weekdayOrWeekend(.Monday) // Returns Weekday
weekdayOrWeekend(.Saturday) // Returns Weekend
In the code above, only Saturday and Sunday would return Weekend, and all other Day values passed in would return Weekday. Hope that helps illustrate the point! Let me know if you have another other questions.
Cindy Lea
Courses Plus Student 6,497 PointsYou can, but they probably are showing you the different cases so you can see how it works with more cases. Once you understand the concept, you can always simplify.