Swift – enum’s rawValue property not recognized

enumsswift

I'm using Xcode 6's playground to try out enums in Swift:

enum Rank: String
{
    case One = "One", Two="Two"

    init(rawValue : String)
    {
        self.rawValue = rawValue
    }
}

I want to override init so that the enum can be initialized using it's rawValue as argument. But I get an error:

enter image description here

But according to the Apple's Swift guide my code should be correct.

Best Solution

The conversion methods between enums and their raw values changed between Xcode 6.0 and Xcode 6.1. The fromRaw() and toRaw() method have been replaced by a (failable) initializer and a rawValue property:

Xcode 6.0:

// raw value to enum:
if let rank = Rank.fromRaw("One") { }

// enum to raw value:
let str = rank.toRaw()

Xcode 6.1:

// raw value to enum:
if let rank = Rank(rawValue: "One") { }

// enum to raw value:
let str = rank.rawValue