Guest User

Untitled

a guest
Aug 14th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. enum SwitchStatus {
  2. case on
  3. case off
  4. }
  5.  
  6. var switchStatus: SwitchStatus = .off
  7.  
  8. func flipSwitch() -> SwitchStatus {
  9. return !switchStatus
  10. }
  11.  
  12. return switchStatus == .on ? .off : .on
  13.  
  14. prefix func !(arg: SwitchStatus) -> SwitchStatus
  15.  
  16. enum SwitchStatus {
  17. case on
  18. case off
  19.  
  20. mutating func toggle() {
  21. switch self {
  22. case .on: self = .off
  23. case .off: self = .on
  24. }
  25. }
  26. }
  27.  
  28. var switchStatus: SwitchStatus = .off
  29. // ...
  30. switchStatus.toggle() // Now it is on
Add Comment
Please, Sign In to add comment