Skip to content

Commit 01753a0

Browse files
committed
fromRaw() and toRaw() is replaced with rawValue
1 parent c36d530 commit 01753a0

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

source/chapter1/02_a_swift_tour.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -531,23 +531,23 @@ enum Rank: Int {
531531
case .King:
532532
return "king"
533533
default:
534-
return String(self.toRaw())
534+
return String(self.rawValue())
535535
}
536536
}
537537
}
538538
let ace = Rank.Ace
539-
let aceRawValue = ace.toRaw()
539+
let aceRawValue = ace.rawValue()
540540
```
541541

542542
> 练习:
543543
> 写一个函数,通过比较它们的原始值来比较两个`Rank`值。
544544
545545
在上面的例子中,枚举原始值的类型是`Int`,所以你只需要设置第一个原始值。剩下的原始值会按照顺序赋值。你也可以使用字符串或者浮点数作为枚举的原始值。
546546

547-
使用`toRaw``fromRaw`函数来在原始值和枚举值之间进行转换
547+
使用'rawValue'在原始值和枚举值之间进行转换
548548

549549
```swift
550-
if let convertedRank = Rank.fromRaw(3) {
550+
if let convertedRank = Rank(rawValue: 3) {
551551
let threeDescription = convertedRank.simpleDescription()
552552
}
553553
```

0 commit comments

Comments
 (0)