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 ```swift
enum OnOffSwitch: Togglable { enum OnOffSwitch: Togglable {
case Off, On case off, on
mutating func toggle() { mutating func toggle() {
switch self { switch self {
case Off: case .off:
self = On self = .on
case On: case .on:
self = Off self = .off
} }
} }
} }
var lightSwitch = OnOffSwitch.Off var lightSwitch = OnOffSwitch.off
lightSwitch.toggle() lightSwitch.toggle()
// lightSwitch 现在的值为 .On // lightSwitch 现在的值为 .On
``` ```