Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- enum SwitchStatus {
- case on
- case off
- }
- var switchStatus: SwitchStatus = .off
- func flipSwitch() -> SwitchStatus {
- return !switchStatus
- }
- return switchStatus == .on ? .off : .on
- prefix func !(arg: SwitchStatus) -> SwitchStatus
- enum SwitchStatus {
- case on
- case off
- mutating func toggle() {
- switch self {
- case .on: self = .off
- case .off: self = .on
- }
- }
- }
- var switchStatus: SwitchStatus = .off
- // ...
- switchStatus.toggle() // Now it is on
Add Comment
Please, Sign In to add comment