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 trialBradley Jackson
2,668 PointsRetrieving Enum Raw Value
Hello everyone,
I passed the task & understand the concept of:
enum Speed: Int { case Slow = 10 case Medium = 50 case Fast = 100 }
var turtleSpeed = Speed.Slow.rawValue
But I am reading the documentation of Swift, and it states for the example:
enum Planet: Int { case Mercury = 1, Venus, Earth, Mars, Jupiter, Saturn, Uranus, Neptune }”
let earthsOrder = Planet.Earth.toRaw() // earthsOrder is 3
So my question is: What does this "toRaw()" function do?
var turtleSpeed = Speed.Slow.toRaw()
Any answer or elaboration would be great!
1 Answer
Ben Griffith
5,808 PointsAccording to the changelog "fromRaw()/toRaw()" has been replaced by rawValue in Xcode 6.1
"Xcode produces fixit hints to move code from the old-style “fromRaw()/toRaw()” enum APIs to the new style-initializer and “rawValue” property. (18216832)"
Bradley Jackson
2,668 PointsBradley Jackson
2,668 PointsOh! That's pretty neat actually... Thanks for the help.