We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent c36d530 commit 01753a0Copy full SHA for 01753a0
source/chapter1/02_a_swift_tour.md
@@ -531,23 +531,23 @@ enum Rank: Int {
531
case .King:
532
return "king"
533
default:
534
- return String(self.toRaw())
+ return String(self.rawValue())
535
}
536
537
538
let ace = Rank.Ace
539
-let aceRawValue = ace.toRaw()
+let aceRawValue = ace.rawValue()
540
```
541
542
> 练习:
543
> 写一个函数,通过比较它们的原始值来比较两个`Rank`值。
544
545
在上面的例子中,枚举原始值的类型是`Int`,所以你只需要设置第一个原始值。剩下的原始值会按照顺序赋值。你也可以使用字符串或者浮点数作为枚举的原始值。
546
547
-使用`toRaw`和`fromRaw`函数来在原始值和枚举值之间进行转换。
+使用'rawValue'在原始值和枚举值之间进行转换。
548
549
```swift
550
-if let convertedRank = Rank.fromRaw(3) {
+if let convertedRank = Rank(rawValue: 3) {
551
let threeDescription = convertedRank.simpleDescription()
552
553
0 commit comments