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

Abdurahman Sharif
Abdurahman Sharif
1,205 Points

please help. I don't know what i'm missing in this challenge using raw values and enums.

i looked over the video several times, but his example wasn't like this one. this one is easier i'm sure, what am i over thinking?. please help

enum.swift
enum Speed: Int {
    case Slow = 10
    case Medium = 50
    case Fast = 100
}
let turtleSpeed = Speed(rawValue: 10)

4 Answers

Give this a try:

var turtleSpeed = Speed.Slow.rawValue
Abdurahman Sharif
Abdurahman Sharif
1,205 Points

ohhhh. but why do i have to do it that way? is what you did the same as what i did?. or am i completely off?

thanks by the way

You're not completely off, no - the rawValue access is a little strange. I wouldn't worry too much about it.

As always, remember to have a look through the documentation. That really can help you and you do get used to it over time.

I just Googled Swift Enum Rawvalue and got this link which does help your question if you scroll around a bit.

Don't get me wrong, by all means ask in here, but the documentation is also a great help!

https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Enumerations.html

The challenge was to get the raw value from Slow, not to pass it "10", as in the above where you have: Speed(rawValue: 10). Their example with Coins was in the format: Coin.Penny.rawValue