Created
March 9, 2020 18:00
-
-
Save macrael/5f2869ded459e1f4a37c788984e75a37 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
| import Foundation | |
| private let tapInterval = 0.2 | |
| enum DoubleTap { | |
| case nope | |
| case firstDown(Date) | |
| case firstUp(Date) | |
| case secondDown(Date) | |
| case doubleTapped | |
| mutating func down() { | |
| switch self { | |
| case .nope: | |
| print("nope down") | |
| self = .firstDown(Date.init()) | |
| case .firstDown: | |
| print("ERROR, First Down Down") | |
| self = .nope | |
| case .firstUp(let upAt): | |
| print("first up down") | |
| if upAt.timeIntervalSinceNow > -tapInterval { | |
| self = .secondDown(Date.init()) | |
| } else { | |
| self = .firstDown(Date.init()) | |
| } | |
| case .secondDown: | |
| print("ERROR, Second Down Down") | |
| self = .nope | |
| case .doubleTapped: | |
| print("DOUBLE TAPPED DOWN???") | |
| self = .firstDown(Date.init()) | |
| } | |
| } | |
| mutating func up() { | |
| switch self { | |
| case .nope: | |
| print("ERROR NOPE UP") | |
| case .firstDown(let downAt): | |
| print("first down up") | |
| if downAt.timeIntervalSinceNow > -tapInterval { | |
| self = .firstUp(Date.init()) | |
| } else { | |
| self = .nope | |
| } | |
| case .firstUp: | |
| print("ERROR, First Up Up") | |
| self = .nope | |
| case .secondDown(let downAt): | |
| print("second down up") | |
| if downAt.timeIntervalSinceNow > -tapInterval { | |
| self = .doubleTapped | |
| } else { | |
| self = .nope | |
| } | |
| case .doubleTapped: | |
| print("DOUBLE TAPPED UP ERR") | |
| self = .nope | |
| } | |
| } | |
| init() { | |
| self = .nope | |
| } | |
| mutating func reset() { | |
| self = .nope | |
| } | |
| func doubleTapped() -> Bool { | |
| switch self { | |
| case .doubleTapped: | |
| return true | |
| default: | |
| return false | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment