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:
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()
andtoRaw()
method have been replaced by a (failable) initializer and arawValue
property:Xcode 6.0:
Xcode 6.1: