Created
June 29, 2018 12:27
-
-
Save jonathanduty/9645169175c6d7b4ff25b2b573a53966 to your computer and use it in GitHub Desktop.
Device+Extensions.swift
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 UIKit | |
struct Device { | |
let ran: Bool | |
@discardableResult static func whenIphoneX(_ block: () -> Void) -> Device { | |
return runIfTrue(Device.isIphoneX, block: block) | |
} | |
@discardableResult static func whenNotIphoneX(_ block: () -> Void) -> Device { | |
return runIfFalse(Device.isIphoneX, block: block) | |
} | |
@discardableResult static func whenIphone8Plus(_ block: () -> Void) -> Device { | |
return runIfTrue(Device.isIphone8Plus, block: block) | |
} | |
static var isIphoneX: Bool | |
{ | |
return mainScreenHeightGreaterThan(height:800) | |
} | |
static var isIphone8Plus: Bool | |
{ | |
return mainScreenHeightGreaterThan(height:700) | |
} | |
static func mainScreenHeightGreaterThan(height: Int) -> Bool { | |
return UIScreen.main.bounds.size.height >= CGFloat(height) | |
} | |
static fileprivate func runIfTrue(_ run: Bool, block: () -> Void) -> Device { | |
if run { | |
block() | |
} | |
return Device(ran: run) | |
} | |
static fileprivate func runIfFalse(_ run: Bool, block: () -> Void) -> Device { | |
if run == false { | |
block() | |
} | |
return Device(ran: run) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment