We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 01753a0 commit cf19347Copy full SHA for cf19347
source-tw/chapter1/02_a_swift_tour.md
@@ -513,23 +513,23 @@ enum Rank: Int {
513
case .King:
514
return "king"
515
default:
516
- return String(self.toRaw())
+ return String(self.rawValue())
517
}
518
519
520
let ace = Rank.Ace
521
-let aceRawValue = ace.toRaw()
+let aceRawValue = ace.rawValue()
522
```
523
524
> 練習:
525
> 寫一個函數,通過比較它們的原始值來比較兩個`Rank`值。
526
527
在上面的例子中,枚舉原始值的類型是`Int`,所以你只需要設置第一個原始值。剩下的原始值會按照順序賦值。你也可以使用字符串或者浮點數作為枚舉的原始值。
528
529
-使用`toRaw`和`fromRaw`函數來在原始值和枚舉值之間進行轉換。
+使用`rawValue`來在原始值和枚舉值之間進行轉換。
530
531
```swift
532
-if let convertedRank = Rank.fromRaw(3) {
+if let convertedRank = Rank(rawValue: 3) {
533
let threeDescription = convertedRank.simpleDescription()
534
535
0 commit comments