Skip to content

Instantly share code, notes, and snippets.

@nvkiet
Created March 31, 2015 10:05
Show Gist options
  • Select an option

  • Save nvkiet/fc71ae008fd22cc62af3 to your computer and use it in GitHub Desktop.

Select an option

Save nvkiet/fc71ae008fd22cc62af3 to your computer and use it in GitHub Desktop.
How to make a enum conform to a protocol in Swift.
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