Created
May 23, 2017 10:36
-
-
Save jonathanduty/c0738f67650d0a2a8e1be89e29a44cd7 to your computer and use it in GitHub Desktop.
Device
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
| struct Device { | |
| let ran: Bool | |
| @discardableResult static func when4sOrSmaller(_ block: () -> Void) -> Device { | |
| return runBlockIfTrue(UIScreen.is4sOrSmaller, block: block) | |
| } | |
| @discardableResult static func when5sOrSmaller(_ block: () -> Void) -> Device { | |
| return runBlockIfTrue(UIScreen.is5sOrSmaller, block: block) | |
| } | |
| func otherwise(_ block: () -> Void) { | |
| if !ran { | |
| block() | |
| } | |
| } | |
| static fileprivate func runBlockIfTrue(_ fn: () -> Bool, block: () -> Void) -> Device { | |
| let run = fn() | |
| if run { | |
| block() | |
| } | |
| return Device(ran: run) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment