Skip to content

Instantly share code, notes, and snippets.

@perpeer
Created May 26, 2020 16:47
Show Gist options
  • Select an option

  • Save perpeer/780acebeb651f40554ef21d8ba8c9437 to your computer and use it in GitHub Desktop.

Select an option

Save perpeer/780acebeb651f40554ef21d8ba8c9437 to your computer and use it in GitHub Desktop.
Toggleable Or Reversible Enum
protocol Toggleable {
mutating func toggle()
}
enum CardOrientation: String, Toggleable {
case Horizontal = "hor"
case Vertical = "ver"
mutating func toggle() {
switch self {
case .Horizontal:
self = .Vertical
case .Vertical:
self = .Horizontal
}
}
}
var orientation: CardOrientation = .Horizontal
orientation.toggle()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment