Skip to content

Commit cf19347

Browse files
committedOct 26, 2014
fromRaw() and toRaw is replaced with 'rawValue'

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed
 

‎source-tw/chapter1/02_a_swift_tour.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -513,23 +513,23 @@ enum Rank: Int {
513513
case .King:
514514
return "king"
515515
default:
516-
return String(self.toRaw())
516+
return String(self.rawValue())
517517
}
518518
}
519519
}
520520
let ace = Rank.Ace
521-
let aceRawValue = ace.toRaw()
521+
let aceRawValue = ace.rawValue()
522522
```
523523

524524
> 練習:
525525
> 寫一個函數,通過比較它們的原始值來比較兩個`Rank`值。
526526
527527
在上面的例子中,枚舉原始值的類型是`Int`,所以你只需要設置第一個原始值。剩下的原始值會按照順序賦值。你也可以使用字符串或者浮點數作為枚舉的原始值。
528528

529-
使用`toRaw``fromRaw`函數來在原始值和枚舉值之間進行轉換
529+
使用`rawValue`來在原始值和枚舉值之間進行轉換
530530

531531
```swift
532-
if let convertedRank = Rank.fromRaw(3) {
532+
if let convertedRank = Rank(rawValue: 3) {
533533
let threeDescription = convertedRank.simpleDescription()
534534
}
535535
```

0 commit comments

Comments
 (0)
Please sign in to comment.