Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS Enumerations and Optionals in Swift Introduction to Enumerations Getting Rid of Strings

Kanish Chhabra
Kanish Chhabra
2,151 Points

Confusion with return values of the Switch statement

While using an enum, when we pass an enum value to a switch and return something from different cases, and then we use the returned value as a reference fo another function. My question is where do these return values are stored if we don't store them in a variable or a constant? https://teamtreehouse.com/library/getting-rid-of-strings please follow this video and I hope you'll understand what I am asking. Please help!

We just built the enums and the function, we did not actually use them.

To use them we will store the values. Each assignment operator I use below is a potential place to store the values.

Your goal is to know whether or not to turn off notifications. let turnOffNotifications =

Turning off notifications is based on if today is a weekend let turnOffNotification = if today is a weekend

We know if today is a weekend by if the day is a Saturday or Sunday let turnOffNotification = if today is a weekend = if today is Saturday or Sunday

We can know if today is Saturday or Sunday in a couple of ways. We can use swift dates or hardcode the day as a string. Using enum, we will likely get the day of the week from Swift dates. By using enum we ensure that the day is only going to be one of the 7 day members (spelled and captialized correctly) and nothing else, otherwise the compiler will complain.

Here is the final chain let turnOffNotification = if today is a weekend = if today is Saturday or Sunday = get date from Swift dates

1 Answer

You have the option to store them in a variable or a constant but you don't have to do anything with the return values if you want, they will still perform whatever actions you put in the method but you can ignore the return value, its entirely up to you