Skip to content

Instantly share code, notes, and snippets.

@quintonwall
Created September 28, 2017 15:12
Show Gist options
  • Save quintonwall/b189ac78a06183129c804e81e9df980d to your computer and use it in GitHub Desktop.
Save quintonwall/b189ac78a06183129c804e81e9df980d to your computer and use it in GitHub Desktop.
UIDevice extension to make working with device basics easier
//
//
//
// Created by QUINTON WALL on 7/31/16.
// Copyright © 2016 Quinton Wall. All rights reserved.
//
import UIKit
public extension UIDevice {
public static func IS_568_SCREEN() -> Bool {
return UIScreen.main.bounds.size.height == 568
}
public static func IS_IPHONE() -> Bool {
return (UIDevice.current.model as NSString).range(of: "iPhone").location != NSNotFound
}
public static func IS_IPOD() -> Bool {
return ((UIDevice.current.model as NSString).range(of: "iPod").location != NSNotFound)
}
public static func IS_IPAD() -> Bool {
return ((UIDevice.current.model as NSString).range(of: "iPad").location != NSNotFound)
}
public static func IS_IOS7_OR_GREATER() -> Bool {
return SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v: "7")
}
public static func IS_IOS8_OR_GREATER() -> Bool {
return SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v: "8")
}
public static func IS_IOS9_OR_GREATER() -> Bool {
return SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v: "9")
}
public static func IS_IOS10_OR_GREATER() -> Bool {
return SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v: "10")
}
public static func IS_IOS11_OR_GREATER() -> Bool {
return SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v: "11")
}
public static func SYSTEM_VERSION_EQUAL_TO(v: String) -> Bool {
return UIDevice.current.systemVersion.compare(v, options: .numeric, range: nil, locale: nil) == .orderedSame
}
public static func SYSTEM_VERSION_GREATER_THAN(v: String) -> Bool {
return UIDevice.current.systemVersion.compare(v, options: .numeric, range: nil, locale: nil) == .orderedDescending
}
public static func SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v: String) -> Bool {
return UIDevice.current.systemVersion.compare(v, options: .numeric, range: nil, locale: nil) != .orderedAscending
}
public static func SYSTEM_VERSION_LESS_THAN(v: String) -> Bool {
return UIDevice.current.systemVersion.compare(v, options: .numeric, range: nil, locale: nil) == .orderedAscending
}
public static func SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v: String) -> Bool {
return UIDevice.current.systemVersion.compare(v, options: .numeric, range: nil, locale: nil) != .orderedDescending
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment