在 Apple 的 swift book 中,有一个枚举示例。它允许您将原始 Int 转换为枚举等级。但是,当我尝试删除 if 语句时,代码给了我
操场执行失败:错误::30:13:错误:“排名?” 没有名为“simpleDescription”的成员
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()