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 trialarnavthecoder
3,453 PointsError about return enum.case.rawValue
In the beginning of the video Mr. Amit's code has no error in the function daysTillWeekend. In my code it says "Day does not have a member named 'rawValue'. Will someone help me?
2 Answers
Chris Shaw
26,676 PointsHi arnavthecoder,
In order for an enum
to register the property rawValue
you need to assign an explicit type to it which matches the initial case
value, for example.
enum Days: Int {
case Monday = 1, Tuesday, Wednesday, Thursday, Friday,
Saturday, Sunday
}
println(Days.Monday.rawValue)
In the above example I've assigned the type Int
which initialises the rawValue
property and sets a requirement that the first case
statement must have a value, because I've used an Int
type all I need to do is set the first case
statement to 1 and Swift will do the rest, for strings we need to define each value.
Hope that helps.
Mayank Chopra
2,608 PointsI had the same problem, looks like .rawValue has been changed to .toRaw() by Swift