Skip to content

Instantly share code, notes, and snippets.

@vincefried
Created March 19, 2019 09:58
Show Gist options
  • Save vincefried/48ee63c8a27b24020e3dd63099ea1d81 to your computer and use it in GitHub Desktop.
Save vincefried/48ee63c8a27b24020e3dd63099ea1d81 to your computer and use it in GitHub Desktop.
//
// 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