Created
April 3, 2015 10:25
-
-
Save boylee1111/ff2ad3dcb0a69b92adb4 to your computer and use it in GitHub Desktop.
A Swift Tour. Write an enumeration that conforms to this protocol.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protocol ExampleProtocol { | |
var simpleDescription: String { get } | |
mutating func adjust() | |
} | |
enum SimpleEnum : String, ExampleProtocol { | |
case Before = "", After = " (whatever)" | |
var simpleDescription: String { | |
get { | |
return "A simple enum." + self.rawValue | |
} | |
} | |
mutating func adjust() { | |
self = .After | |
} | |
} | |
var c = SimpleEnum.Before | |
c.adjust() | |
c.simpleDescription |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, I typed your code but Xcode(8.3.2) gave me a compiler error for raw type error. The codes in the following are modified according to your codes.