Skip to content

Instantly share code, notes, and snippets.

@jonathanduty
Created May 23, 2017 10:36
Show Gist options
  • Select an option

  • Save jonathanduty/c0738f67650d0a2a8e1be89e29a44cd7 to your computer and use it in GitHub Desktop.

Select an option

Save jonathanduty/c0738f67650d0a2a8e1be89e29a44cd7 to your computer and use it in GitHub Desktop.
Device
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