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 trial

iOS Swift Enums and Structs Enums Enum Members and Raw Values

Rob Bartlett
Rob Bartlett
6,741 Points

Extending the Example

I am trying to take the example in this video one step further so that if the return of daysTillWeekend is less than or equal to 0 (that is, if your input is Saturday or Sunday), it returns a message that it is currently the weekend.

I've tried some many variations trying to get this to work, but what I want to do boils down to:

func daysTillWeekend(day: Day) -> Int {
    return Day.Saturday.rawValue - day.rawValue
    if <= 0
    println "It's the weekend now!"}

How could I get this to work?

2 Answers

Jhoan Arango
Jhoan Arango
14,575 Points

Hello Rob:

I’m not sure if this is what you are trying to do, but maybe you can do something like this.

func daysTillWeekend(day: Day) -> Int{

    if Day.Saturday.rawValue - day.rawValue <= 1 {
        print("It's a weekend")
    } else {
        print("It's Not a weekend")
    }
    return Day.Saturday.rawValue - day.rawValue   
}
Rob Bartlett
Rob Bartlett
6,741 Points

Thanks Jhoan, this put me on the right track. Frustrating how close I was to getting it right.