Update 22_Protocols.md (#678)

语法不对,参考官方文档修改过来了
This commit is contained in:
xiaox0321
2017-01-03 18:29:54 +08:00
committed by 安正超
parent 33e4f02ee2
commit 59e630f19e

View File

@ -208,17 +208,17 @@ protocol Togglable {
```swift
enum OnOffSwitch: Togglable {
case Off, On
mutating func toggle() {
switch self {
case Off:
self = On
case On:
self = Off
}
}
case off, on
mutating func toggle() {
switch self {
case .off:
self = .on
case .on:
self = .off
}
}
}
var lightSwitch = OnOffSwitch.Off
var lightSwitch = OnOffSwitch.off
lightSwitch.toggle()
// lightSwitch 现在的值为 .On
```