In the swift book by Apple, there is an enum example. It lets you convert a raw Int to a enum rank. However when I try to remove the if statement, the code gives me
Playground execution failed: error: :30:13: error: 'Rank?' does not have a member named 'simpleDesciption'
enum Rank: Int {
case Ace = 1
case Two, Three, Four, Five, Six, Seven, Eight, Nine, Ten
case Jack, Queen, King
func simpleDesciption() -> String {
switch self {
case .Ace:
return "ace"
case .Jack:
return "jack"
case .Queen:
return "queen"
case .King:
return "king"
default:
return String(self.toRaw())
}
}
}
if let convertedRank = Rank.fromRaw(1){
let threeDescription = convertedRank.simpleDesciption()
}
// Why does it need to be wrapped in a if statement?
let convertedRank = Rank.fromRaw(1)
let threeDescription = convertedRank.simpleDesciption()