From 59e630f19ebd151297788af359d410d00f8b3590 Mon Sep 17 00:00:00 2001 From: xiaox0321 Date: Tue, 3 Jan 2017 18:29:54 +0800 Subject: [PATCH] Update 22_Protocols.md (#678) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 语法不对,参考官方文档修改过来了 --- source/chapter2/22_Protocols.md | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/source/chapter2/22_Protocols.md b/source/chapter2/22_Protocols.md index 2c119533..519c24ca 100644 --- a/source/chapter2/22_Protocols.md +++ b/source/chapter2/22_Protocols.md @@ -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 ```