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

Harry Tran
Harry Tran
10,618 Points

rawValue or hashValue?

My xCode playground is not accepting .rawValue in my daysTillWeekend function, but rather when gives me the option of a hashValue when I start typing. It seems to return the correct answer when I put in Day.Friday into the function the answer comes back as 1.

But the code breaks if I use .rawValue

Harry Tran
Harry Tran
10,618 Points

Looks like it's an issue with my Xcode, I have version 6.0.1 and it doesn't appear that Apple used rawValue until 6.1

2 Answers

Try .toRaw() so Day.Saturday.toRaw() returns 6.

The .rawValue is all fine in Xcode 6.1 so you may need to update.

Harry Tran
Harry Tran
10,618 Points

Wonderful, thank you for helping me out Rob