Created
March 19, 2019 09:58
-
-
Save vincefried/48ee63c8a27b24020e3dd63099ea1d81 to your computer and use it in GitHub Desktop.
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
// | |
// Ampel.swift | |
// Ampel | |
// | |
// Created by Vincent Friedrich on 19.03.19. | |
// Copyright © 2019 neoxapps. All rights reserved. | |
// | |
import Foundation | |
enum AmpelColor { | |
case red, yellow, green | |
} | |
protocol AmpelDelegate { | |
func ampelColorDidChange(to color: AmpelColor) | |
} | |
class Ampel { | |
var delegate: AmpelDelegate? | |
var color: AmpelColor = .red | |
func next() { | |
switch color { | |
case .red: | |
self.color = .yellow | |
case .yellow: | |
self.color = .green | |
case .green: | |
self.color = .red | |
} | |
delegate?.ampelColorDidChange(to: self.color) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment