我一直在下面我的代碼行收到錯誤:「排名」Swift:'Rank?沒有名爲'simpleDescription'的成員?
let rank1desc = rank1Conv.simpleDescription();
let rank2desc = rank2Conv.simpleDescription();
聲稱該沒有名爲'simpleDescription'的成員。我發現這很奇怪,因爲我根據Apple的教程編寫了這些代碼,並且沒有在Rank的任何地方實施和選擇任何東西?暗示我有。我很想知道爲什麼它給了我這個錯誤,以及如果確實存在可選的來源。非常感謝!
這裏是我的代碼:
enum Rank: Int{
case Ace = 1;
case Two = 2, Three = 3, Four = 4, Five = 5, Six = 6, Seven = 7, Eight = 8, Nine = 9, Ten = 10;
case Jack = 11, Queen = 12, King = 13;
func simpleDescription() -> String{
switch self{
case .Ace:
return "Ace";
case .Jack:
return "Jack";
case .Queen:
return "Queen";
case .King:
return "King";
default:
return String(self.toRaw())
}
}
}
let ace = Rank.Ace;
let aceRawValue = ace.toRaw();
func compRank(rank1: Int, rank2: Int) -> String{
let rank1Conv = Rank.fromRaw(rank1);
let rank2Conv = Rank.fromRaw(rank2)
let rank1desc = rank1Conv.simpleDescription();
let rank2desc = rank2Conv.simpleDescription();
if(rank1 > rank2){
return rank1desc;
}
else if(rank2>rank1){
return rank2desc;
}
else{
return "They are equal";
}
}
compRank(rank1: 3, rank2: 2);
謝謝@alvin! –
@ JonathanO'Farrell:沒問題! –