Created
March 31, 2015 10:05
-
-
Save nvkiet/fc71ae008fd22cc62af3 to your computer and use it in GitHub Desktop.
How to make a enum conform to a protocol in Swift.
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
| enum SimpleEnum : ExampleProtocol { | |
| case Base, Adjusted | |
| var simpleDescription: String { | |
| get { | |
| return self.getDescription() | |
| } | |
| } | |
| func getDescription() -> String { | |
| switch self { | |
| case .Base: | |
| return "A simple description of enum" | |
| case .Adjusted: | |
| return "Adjusted description of enum" | |
| default: | |
| return "default description" | |
| } | |
| } | |
| mutating func adjust() -> Void{ | |
| self = SimpleEnum.Adjusted | |
| } | |
| } | |
| var c = SimpleEnum.Base | |
| c.simpleDescription | |
| c.adjust() | |
| c.simpleDescription | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment