Skip to content

Instantly share code, notes, and snippets.

@imkevinxu
Last active March 4, 2023 16:09
Show Gist options
  • Select an option

  • Save imkevinxu/2bb1197552b095ab25c8 to your computer and use it in GitHub Desktop.

Select an option

Save imkevinxu/2bb1197552b095ab25c8 to your computer and use it in GitHub Desktop.

Revisions

  1. imkevinxu revised this gist Jun 21, 2015. 1 changed file with 146 additions and 63 deletions.
    209 changes: 146 additions & 63 deletions Device.swift
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@
    // Device.swift
    // imHome
    //
    // Created by Kevin Xu on 2/9/15.
    // Created by Kevin Xu on 2/9/15. Updated on 6/20/15.
    // Copyright (c) 2015 Alpha Labs, Inc. All rights reserved.
    //

    @@ -11,197 +11,280 @@ import Foundation
    // MARK: - Device Structure

    struct Device {

    // MARK: - Singletons
    static var currentDevice: UIDevice {

    static var TheCurrentDevice: UIDevice {
    struct Singleton {
    static let device = UIDevice.currentDevice()
    }
    return Singleton.device
    }
    static var currentDeviceVersion: Float {

    static var TheCurrentDeviceVersion: Float {
    struct Singleton {
    static let version = UIDevice.currentDevice().systemVersion.floatValue
    }
    return Singleton.version
    }
    static var currentDeviceHeight: CGFloat {

    static var TheCurrentDeviceHeight: CGFloat {
    struct Singleton {
    static let height = UIScreen.mainScreen().bounds.size.height
    }
    return Singleton.height
    }

    // MARK: - Device Idiom Checks


    static var PHONE_OR_PAD: String {
    if isPhone() {
    return "iPhone"
    } else if isPad() {
    return "iPad"
    }
    return "Not iPhone nor iPad"
    }

    static var DEBUG_OR_RELEASE: String {
    #if DEBUG
    return "Debug"
    #else
    return "Release"
    #endif
    }

    static var SIMULATOR_OR_DEVICE: String {
    #if (arch(i386) || arch(x86_64)) && os(iOS)
    return "Simulator"
    #else
    return "Device"
    #endif
    }

    static var CURRENT_DEVICE: String {
    return GBDeviceInfo.deviceInfo().modelString
    }

    static func isPhone() -> Bool {
    return currentDevice.userInterfaceIdiom == .Phone
    return TheCurrentDevice.userInterfaceIdiom == .Phone
    }

    static func isPad() -> Bool {
    return currentDevice.userInterfaceIdiom == .Pad
    return TheCurrentDevice.userInterfaceIdiom == .Pad
    }

    static func isDebug() -> Bool {
    return DEBUG_OR_RELEASE == "Debug"
    }

    static func isRelease() -> Bool {
    return DEBUG_OR_RELEASE == "Release"
    }

    static func isSimulator() -> Bool {
    return SIMULATOR_OR_DEVICE == "Simulator"
    }

    static func isDevice() -> Bool {
    return SIMULATOR_OR_DEVICE == "Device"
    }

    // MARK: - Device Version Checks

    enum Versions: Float {
    case Five = 5.0
    case Six = 6.0
    case Seven = 7.0
    case Eight = 8.0
    case Nine = 9.0
    }

    static func isVersion(version: Versions) -> Bool {
    return currentDeviceVersion >= version.rawValue && currentDeviceVersion < (version.rawValue + 1.0)
    return TheCurrentDeviceVersion >= version.rawValue && TheCurrentDeviceVersion < (version.rawValue + 1.0)
    }

    static func isVersionOrLater(version: Versions) -> Bool {
    return currentDeviceVersion >= version.rawValue
    return TheCurrentDeviceVersion >= version.rawValue
    }

    static func isVersionOrEarlier(version: Versions) -> Bool {
    return currentDeviceVersion < (version.rawValue + 1.0)
    return TheCurrentDeviceVersion < (version.rawValue + 1.0)
    }


    static var CURRENT_VERSION: String {
    return "\(TheCurrentDeviceVersion)"
    }

    // MARK: iOS 5 Checks

    static func IS_OS_5() -> Bool {
    return isVersion(.Five)
    }

    static func IS_OS_5_OR_LATER() -> Bool {
    return isVersionOrLater(.Five)
    }

    static func IS_OS_5_OR_EARLIER() -> Bool {
    return isVersionOrEarlier(.Five)
    }

    // MARK: iOS 6 Checks

    static func IS_OS_6() -> Bool {
    return isVersion(.Six)
    }

    static func IS_OS_6_OR_LATER() -> Bool {
    return isVersionOrLater(.Six)
    }

    static func IS_OS_6_OR_EARLIER() -> Bool {
    return isVersionOrEarlier(.Six)
    }

    // MARK: iOS 7 Checks

    static func IS_OS_7() -> Bool {
    return isVersion(.Seven)
    }

    static func IS_OS_7_OR_LATER() -> Bool {
    return isVersionOrLater(.Seven)
    }

    static func IS_OS_7_OR_EARLIER() -> Bool {
    return isVersionOrEarlier(.Seven)
    }

    // MARK: iOS 8 Checks

    static func IS_OS_8() -> Bool {
    return isVersion(.Eight)
    }

    static func IS_OS_8_OR_LATER() -> Bool {
    return isVersionOrLater(.Eight)
    }

    static func IS_OS_8_OR_EARLIER() -> Bool {
    return isVersionOrEarlier(.Eight)
    }


    // MARK: iOS 9 Checks

    static func IS_OS_9() -> Bool {
    return isVersion(.Nine)
    }

    static func IS_OS_9_OR_LATER() -> Bool {
    return isVersionOrLater(.Nine)
    }

    static func IS_OS_9_OR_EARLIER() -> Bool {
    return isVersionOrEarlier(.Nine)
    }

    // MARK: - Device Size Checks

    enum Heights: CGFloat {
    case Inches_3_5 = 480
    case Inches_4 = 568
    case Inches_4_7 = 667
    case Inches_5_5 = 736
    }

    static func isSize(height: Heights) -> Bool {
    return currentDeviceHeight == height.rawValue
    return TheCurrentDeviceHeight == height.rawValue
    }

    static func isSizeOrLarger(height: Heights) -> Bool {
    return currentDeviceHeight >= height.rawValue
    return TheCurrentDeviceHeight >= height.rawValue
    }

    static func isSizeOrSmaller(height: Heights) -> Bool {
    return currentDeviceHeight <= height.rawValue
    return TheCurrentDeviceHeight <= height.rawValue
    }


    static var CURRENT_SIZE: String {
    if IS_3_5_INCHES() {
    return "3.5 Inches"
    } else if IS_4_INCHES() {
    return "4 Inches"
    } else if IS_4_7_INCHES() {
    return "4.7 Inches"
    } else if IS_5_5_INCHES() {
    return "5.5 Inches"
    }
    return "\(TheCurrentDeviceHeight) Points"
    }

    // MARK: Retina Check

    static func IS_RETINA() -> Bool {
    return UIScreen.mainScreen().respondsToSelector("scale")
    }

    // MARK: 3.5 Inch Checks

    static func IS_3_5_INCHES() -> Bool {
    return isPhone() && isSize(.Inches_3_5)
    }

    static func IS_3_5_INCHES_OR_LARGER() -> Bool {
    return isPhone() && isSizeOrLarger(.Inches_3_5)
    }

    static func IS_3_5_INCHES_OR_SMALLER() -> Bool {
    return isPhone() && isSizeOrSmaller(.Inches_3_5)
    }

    // MARK: 4 Inch Checks

    static func IS_4_INCHES() -> Bool {
    return isPhone() && isSize(.Inches_4)
    }

    static func IS_4_INCHES_OR_LARGER() -> Bool {
    return isPhone() && isSizeOrLarger(.Inches_4)
    }

    static func IS_4_INCHES_OR_SMALLER() -> Bool {
    return isPhone() && isSizeOrSmaller(.Inches_4)
    }

    // MARK: 4.7 Inch Checks

    static func IS_4_7_INCHES() -> Bool {
    return isPhone() && isSize(.Inches_4_7)
    }

    static func IS_4_7_INCHES_OR_LARGER() -> Bool {
    return isPhone() && isSizeOrLarger(.Inches_4_7)
    }

    static func IS_4_7_INCHES_OR_SMALLER() -> Bool {
    return isPhone() && isSizeOrLarger(.Inches_4_7)
    }

    // MARK: 5.5 Inch Checks

    static func IS_5_5_INCHES() -> Bool {
    return isPhone() && isSize(.Inches_5_5)
    }

    static func IS_5_5_INCHES_OR_LARGER() -> Bool {
    return isPhone() && isSizeOrLarger(.Inches_5_5)
    }

    static func IS_5_5_INCHES_OR_SMALLER() -> Bool {
    return isPhone() && isSizeOrLarger(.Inches_5_5)
    }

    // MARK: - International Checks

    static var CURRENT_REGION: String {
    return NSLocale.currentLocale().objectForKey(NSLocaleCountryCode) as! String
    }
    }
  2. imkevinxu revised this gist Feb 16, 2015. 1 changed file with 29 additions and 12 deletions.
    41 changes: 29 additions & 12 deletions Device.swift
    Original file line number Diff line number Diff line change
    @@ -14,6 +14,13 @@ struct Device {

    // MARK: - Singletons

    static var currentDevice: UIDevice {
    struct Singleton {
    static let device = UIDevice.currentDevice()
    }
    return Singleton.device
    }

    static var currentDeviceVersion: Float {
    struct Singleton {
    static let version = UIDevice.currentDevice().systemVersion.floatValue
    @@ -28,6 +35,16 @@ struct Device {
    return Singleton.height
    }

    // MARK: - Device Idiom Checks

    static func isPhone() -> Bool {
    return currentDevice.userInterfaceIdiom == .Phone
    }

    static func isPad() -> Bool {
    return currentDevice.userInterfaceIdiom == .Pad
    }

    // MARK: - Device Version Checks

    enum Versions: Float {
    @@ -135,56 +152,56 @@ struct Device {
    // MARK: 3.5 Inch Checks

    static func IS_3_5_INCHES() -> Bool {
    return isSize(.Inches_3_5)
    return isPhone() && isSize(.Inches_3_5)
    }

    static func IS_3_5_INCHES_OR_LARGER() -> Bool {
    return isSizeOrLarger(.Inches_3_5)
    return isPhone() && isSizeOrLarger(.Inches_3_5)
    }

    static func IS_3_5_INCHES_OR_SMALLER() -> Bool {
    return isSizeOrSmaller(.Inches_3_5)
    return isPhone() && isSizeOrSmaller(.Inches_3_5)
    }

    // MARK: 4 Inch Checks

    static func IS_4_INCHES() -> Bool {
    return isSize(.Inches_4)
    return isPhone() && isSize(.Inches_4)
    }

    static func IS_4_INCHES_OR_LARGER() -> Bool {
    return isSizeOrLarger(.Inches_4)
    return isPhone() && isSizeOrLarger(.Inches_4)
    }

    static func IS_4_INCHES_OR_SMALLER() -> Bool {
    return isSizeOrSmaller(.Inches_4)
    return isPhone() && isSizeOrSmaller(.Inches_4)
    }

    // MARK: 4.7 Inch Checks

    static func IS_4_7_INCHES() -> Bool {
    return isSize(.Inches_4_7)
    return isPhone() && isSize(.Inches_4_7)
    }

    static func IS_4_7_INCHES_OR_LARGER() -> Bool {
    return isSizeOrLarger(.Inches_4_7)
    return isPhone() && isSizeOrLarger(.Inches_4_7)
    }

    static func IS_4_7_INCHES_OR_SMALLER() -> Bool {
    return isSizeOrLarger(.Inches_4_7)
    return isPhone() && isSizeOrLarger(.Inches_4_7)
    }

    // MARK: 5.5 Inch Checks

    static func IS_5_5_INCHES() -> Bool {
    return isSize(.Inches_5_5)
    return isPhone() && isSize(.Inches_5_5)
    }

    static func IS_5_5_INCHES_OR_LARGER() -> Bool {
    return isSizeOrLarger(.Inches_5_5)
    return isPhone() && isSizeOrLarger(.Inches_5_5)
    }

    static func IS_5_5_INCHES_OR_SMALLER() -> Bool {
    return isSizeOrLarger(.Inches_5_5)
    return isPhone() && isSizeOrLarger(.Inches_5_5)
    }
    }
  3. imkevinxu revised this gist Feb 16, 2015. 1 changed file with 62 additions and 24 deletions.
    86 changes: 62 additions & 24 deletions Device.swift
    Original file line number Diff line number Diff line change
    @@ -30,64 +30,102 @@ struct Device {

    // MARK: - Device Version Checks

    enum Versions: Float {
    case Five = 5.0
    case Six = 6.0
    case Seven = 7.0
    case Eight = 8.0
    }

    static func isVersion(version: Versions) -> Bool {
    return currentDeviceVersion >= version.rawValue && currentDeviceVersion < (version.rawValue + 1.0)
    }

    static func isVersionOrLater(version: Versions) -> Bool {
    return currentDeviceVersion >= version.rawValue
    }

    static func isVersionOrEarlier(version: Versions) -> Bool {
    return currentDeviceVersion < (version.rawValue + 1.0)
    }

    // MARK: iOS 5 Checks

    static func IS_OS_5() -> Bool {
    return currentDeviceVersion >= 5.0 && currentDeviceVersion < 6.0
    return isVersion(.Five)
    }

    static func IS_OS_5_OR_LATER() -> Bool {
    return currentDeviceVersion >= 5.0
    return isVersionOrLater(.Five)
    }

    static func IS_OS_5_OR_EARLIER() -> Bool {
    return currentDeviceVersion < 6.0
    return isVersionOrEarlier(.Five)
    }

    // MARK: iOS 6 Checks

    static func IS_OS_6() -> Bool {
    return currentDeviceVersion >= 6.0 && currentDeviceVersion < 7.0
    return isVersion(.Six)
    }

    static func IS_OS_6_OR_LATER() -> Bool {
    return currentDeviceVersion >= 6.0
    return isVersionOrLater(.Six)
    }

    static func IS_OS_6_OR_EARLIER() -> Bool {
    return currentDeviceVersion < 7.0
    return isVersionOrEarlier(.Six)
    }

    // MARK: iOS 7 Checks

    static func IS_OS_7() -> Bool {
    return currentDeviceVersion >= 7.0 && currentDeviceVersion < 8.0
    return isVersion(.Seven)
    }

    static func IS_OS_7_OR_LATER() -> Bool {
    return currentDeviceVersion >= 7.0
    return isVersionOrLater(.Seven)
    }

    static func IS_OS_7_OR_EARLIER() -> Bool {
    return currentDeviceVersion < 8.0
    return isVersionOrEarlier(.Seven)
    }

    // MARK: iOS 8 Checks

    static func IS_OS_8() -> Bool {
    return currentDeviceVersion >= 8.0 && currentDeviceVersion < 9.0
    return isVersion(.Eight)
    }

    static func IS_OS_8_OR_LATER() -> Bool {
    return currentDeviceVersion >= 8.0
    return isVersionOrLater(.Eight)
    }

    static func IS_OS_8_OR_EARLIER() -> Bool {
    return currentDeviceVersion < 9.0
    return isVersionOrEarlier(.Eight)
    }

    // MARK: - Device Size Checks

    enum Heights: CGFloat {
    case Inches_3_5 = 480
    case Inches_4 = 568
    case Inches_4_7 = 667
    case Inches_5_5 = 736
    }

    static func isSize(height: Heights) -> Bool {
    return currentDeviceHeight == height.rawValue
    }

    static func isSizeOrLarger(height: Heights) -> Bool {
    return currentDeviceHeight >= height.rawValue
    }

    static func isSizeOrSmaller(height: Heights) -> Bool {
    return currentDeviceHeight <= height.rawValue
    }

    // MARK: Retina Check

    static func IS_RETINA() -> Bool {
    @@ -97,56 +135,56 @@ struct Device {
    // MARK: 3.5 Inch Checks

    static func IS_3_5_INCHES() -> Bool {
    return currentDeviceHeight == 480
    return isSize(.Inches_3_5)
    }

    static func IS_3_5_INCHES_OR_LARGER() -> Bool {
    return currentDeviceHeight >= 480
    return isSizeOrLarger(.Inches_3_5)
    }

    static func IS_3_5_INCHES_OR_SMALLER() -> Bool {
    return currentDeviceHeight <= 480
    return isSizeOrSmaller(.Inches_3_5)
    }

    // MARK: 4 Inch Checks

    static func IS_4_INCHES() -> Bool {
    return currentDeviceHeight == 568
    return isSize(.Inches_4)
    }

    static func IS_4_INCHES_OR_LARGER() -> Bool {
    return currentDeviceHeight >= 568
    return isSizeOrLarger(.Inches_4)
    }

    static func IS_4_INCHES_OR_SMALLER() -> Bool {
    return currentDeviceHeight <= 568
    return isSizeOrSmaller(.Inches_4)
    }

    // MARK: 4.7 Inch Checks

    static func IS_4_7_INCHES() -> Bool {
    return currentDeviceHeight == 667
    return isSize(.Inches_4_7)
    }

    static func IS_4_7_INCHES_OR_LARGER() -> Bool {
    return currentDeviceHeight >= 667
    return isSizeOrLarger(.Inches_4_7)
    }

    static func IS_4_7_INCHES_OR_SMALLER() -> Bool {
    return currentDeviceHeight <= 667
    return isSizeOrLarger(.Inches_4_7)
    }

    // MARK: 5.5 Inch Checks

    static func IS_5_5_INCHES() -> Bool {
    return currentDeviceHeight == 736
    return isSize(.Inches_5_5)
    }

    static func IS_5_5_INCHES_OR_LARGER() -> Bool {
    return currentDeviceHeight >= 736
    return isSizeOrLarger(.Inches_5_5)
    }

    static func IS_5_5_INCHES_OR_SMALLER() -> Bool {
    return currentDeviceHeight <= 736
    return isSizeOrLarger(.Inches_5_5)
    }
    }
  4. imkevinxu revised this gist Feb 16, 2015. 1 changed file with 44 additions and 44 deletions.
    88 changes: 44 additions & 44 deletions Device.swift
    Original file line number Diff line number Diff line change
    @@ -8,145 +8,145 @@

    import Foundation

    // MARK: - Device Class
    // MARK: - Device Structure

    class Device {
    struct Device {

    // MARK: - Device Properties
    // MARK: - Singletons

    class var currentDeviceVersion: Float {
    static var currentDeviceVersion: Float {
    struct Singleton {
    static let version = UIDevice.currentDevice().systemVersion.floatValue
    }
    return Singleton.version
    }

    class var currentDeviceSize: CGFloat {
    static var currentDeviceHeight: CGFloat {
    struct Singleton {
    static let size = UIScreen.mainScreen().bounds.size.height
    static let height = UIScreen.mainScreen().bounds.size.height
    }
    return Singleton.size
    return Singleton.height
    }

    // MARK: - Device Version Checks

    // MARK: iOS 5 Checks

    class func IS_OS_5() -> Bool {
    static func IS_OS_5() -> Bool {
    return currentDeviceVersion >= 5.0 && currentDeviceVersion < 6.0
    }

    class func IS_OS_5_OR_LATER() -> Bool {
    static func IS_OS_5_OR_LATER() -> Bool {
    return currentDeviceVersion >= 5.0
    }

    class func IS_OS_5_OR_EARLIER() -> Bool {
    static func IS_OS_5_OR_EARLIER() -> Bool {
    return currentDeviceVersion < 6.0
    }

    // MARK: iOS 6 Checks

    class func IS_OS_6() -> Bool {
    static func IS_OS_6() -> Bool {
    return currentDeviceVersion >= 6.0 && currentDeviceVersion < 7.0
    }

    class func IS_OS_6_OR_LATER() -> Bool {
    static func IS_OS_6_OR_LATER() -> Bool {
    return currentDeviceVersion >= 6.0
    }

    class func IS_OS_6_OR_EARLIER() -> Bool {
    static func IS_OS_6_OR_EARLIER() -> Bool {
    return currentDeviceVersion < 7.0
    }

    // MARK: iOS 7 Checks

    class func IS_OS_7() -> Bool {
    static func IS_OS_7() -> Bool {
    return currentDeviceVersion >= 7.0 && currentDeviceVersion < 8.0
    }

    class func IS_OS_7_OR_LATER() -> Bool {
    static func IS_OS_7_OR_LATER() -> Bool {
    return currentDeviceVersion >= 7.0
    }

    class func IS_OS_7_OR_EARLIER() -> Bool {
    static func IS_OS_7_OR_EARLIER() -> Bool {
    return currentDeviceVersion < 8.0
    }

    // MARK: iOS 8 Checks

    class func IS_OS_8() -> Bool {
    static func IS_OS_8() -> Bool {
    return currentDeviceVersion >= 8.0 && currentDeviceVersion < 9.0
    }

    class func IS_OS_8_OR_LATER() -> Bool {
    static func IS_OS_8_OR_LATER() -> Bool {
    return currentDeviceVersion >= 8.0
    }

    class func IS_OS_8_OR_EARLIER() -> Bool {
    static func IS_OS_8_OR_EARLIER() -> Bool {
    return currentDeviceVersion < 9.0
    }

    // MARK: - Device Size Checks

    // MARK: Retina Check

    class func IS_RETINA() -> Bool {
    static func IS_RETINA() -> Bool {
    return UIScreen.mainScreen().respondsToSelector("scale")
    }

    // MARK: 3.5 Inch Checks

    class func IS_3_5_INCHES() -> Bool {
    return currentDeviceSize == 480
    static func IS_3_5_INCHES() -> Bool {
    return currentDeviceHeight == 480
    }

    class func IS_3_5_INCHES_OR_LARGER() -> Bool {
    return currentDeviceSize >= 480
    static func IS_3_5_INCHES_OR_LARGER() -> Bool {
    return currentDeviceHeight >= 480
    }

    class func IS_3_5_INCHES_OR_SMALLER() -> Bool {
    return currentDeviceSize <= 480
    static func IS_3_5_INCHES_OR_SMALLER() -> Bool {
    return currentDeviceHeight <= 480
    }

    // MARK: 4 Inch Checks

    class func IS_4_INCHES() -> Bool {
    return currentDeviceSize == 568
    static func IS_4_INCHES() -> Bool {
    return currentDeviceHeight == 568
    }

    class func IS_4_INCHES_OR_LARGER() -> Bool {
    return currentDeviceSize >= 568
    static func IS_4_INCHES_OR_LARGER() -> Bool {
    return currentDeviceHeight >= 568
    }

    class func IS_4_INCHES_OR_SMALLER() -> Bool {
    return currentDeviceSize <= 568
    static func IS_4_INCHES_OR_SMALLER() -> Bool {
    return currentDeviceHeight <= 568
    }

    // MARK: 4.7 Inch Checks

    class func IS_4_7_INCHES() -> Bool {
    return currentDeviceSize == 667
    static func IS_4_7_INCHES() -> Bool {
    return currentDeviceHeight == 667
    }

    class func IS_4_7_INCHES_OR_LARGER() -> Bool {
    return currentDeviceSize >= 667
    static func IS_4_7_INCHES_OR_LARGER() -> Bool {
    return currentDeviceHeight >= 667
    }

    class func IS_4_7_INCHES_OR_SMALLER() -> Bool {
    return currentDeviceSize <= 667
    static func IS_4_7_INCHES_OR_SMALLER() -> Bool {
    return currentDeviceHeight <= 667
    }

    // MARK: 5.5 Inch Checks

    class func IS_5_5_INCHES() -> Bool {
    return currentDeviceSize == 736
    static func IS_5_5_INCHES() -> Bool {
    return currentDeviceHeight == 736
    }

    class func IS_5_5_INCHES_OR_LARGER() -> Bool {
    return currentDeviceSize >= 736
    static func IS_5_5_INCHES_OR_LARGER() -> Bool {
    return currentDeviceHeight >= 736
    }

    class func IS_5_5_INCHES_OR_SMALLER() -> Bool {
    return currentDeviceSize <= 736
    static func IS_5_5_INCHES_OR_SMALLER() -> Bool {
    return currentDeviceHeight <= 736
    }
    }
  5. imkevinxu revised this gist Feb 10, 2015. 1 changed file with 40 additions and 28 deletions.
    68 changes: 40 additions & 28 deletions Device.swift
    Original file line number Diff line number Diff line change
    @@ -12,66 +12,78 @@ import Foundation

    class Device {

    // MARK: - Device Properties

    class var currentDeviceVersion: Float {
    struct Singleton {
    static let version = UIDevice.currentDevice().systemVersion.floatValue
    }
    return Singleton.version
    }

    class var currentDeviceSize: CGFloat {
    struct Singleton {
    static let size = UIScreen.mainScreen().bounds.size.height
    }
    return Singleton.size
    }

    // MARK: - Device Version Checks

    // MARK: iOS 5 Checks

    class func IS_OS_5() -> Bool {
    return UIDevice.currentDevice().systemVersion.floatValue >= 5.0
    && UIDevice.currentDevice().systemVersion.floatValue < 6.0
    return currentDeviceVersion >= 5.0 && currentDeviceVersion < 6.0
    }

    class func IS_OS_5_OR_LATER() -> Bool {
    return UIDevice.currentDevice().systemVersion.floatValue >= 5.0
    return currentDeviceVersion >= 5.0
    }

    class func IS_OS_5_OR_EARLIER() -> Bool {
    return UIDevice.currentDevice().systemVersion.floatValue < 6.0
    return currentDeviceVersion < 6.0
    }

    // MARK: iOS 6 Checks

    class func IS_OS_6() -> Bool {
    return UIDevice.currentDevice().systemVersion.floatValue >= 6.0
    && UIDevice.currentDevice().systemVersion.floatValue < 7.0
    return currentDeviceVersion >= 6.0 && currentDeviceVersion < 7.0
    }

    class func IS_OS_6_OR_LATER() -> Bool {
    return UIDevice.currentDevice().systemVersion.floatValue >= 6.0
    return currentDeviceVersion >= 6.0
    }

    class func IS_OS_6_OR_EARLIER() -> Bool {
    return UIDevice.currentDevice().systemVersion.floatValue < 7.0
    return currentDeviceVersion < 7.0
    }

    // MARK: iOS 7 Checks

    class func IS_OS_7() -> Bool {
    return UIDevice.currentDevice().systemVersion.floatValue >= 7.0
    && UIDevice.currentDevice().systemVersion.floatValue < 8.0
    return currentDeviceVersion >= 7.0 && currentDeviceVersion < 8.0
    }

    class func IS_OS_7_OR_LATER() -> Bool {
    return UIDevice.currentDevice().systemVersion.floatValue >= 7.0
    return currentDeviceVersion >= 7.0
    }

    class func IS_OS_7_OR_EARLIER() -> Bool {
    return UIDevice.currentDevice().systemVersion.floatValue < 8.0
    return currentDeviceVersion < 8.0
    }

    // MARK: iOS 8 Checks

    class func IS_OS_8() -> Bool {
    return UIDevice.currentDevice().systemVersion.floatValue >= 8.0
    && UIDevice.currentDevice().systemVersion.floatValue < 9.0
    return currentDeviceVersion >= 8.0 && currentDeviceVersion < 9.0
    }

    class func IS_OS_8_OR_LATER() -> Bool {
    return UIDevice.currentDevice().systemVersion.floatValue >= 8.0
    return currentDeviceVersion >= 8.0
    }

    class func IS_OS_8_OR_EARLIER() -> Bool {
    return UIDevice.currentDevice().systemVersion.floatValue < 9.0
    return currentDeviceVersion < 9.0
    }

    // MARK: - Device Size Checks
    @@ -85,56 +97,56 @@ class Device {
    // MARK: 3.5 Inch Checks

    class func IS_3_5_INCHES() -> Bool {
    return UIScreen.mainScreen().bounds.size.height == 480
    return currentDeviceSize == 480
    }

    class func IS_3_5_INCHES_OR_LARGER() -> Bool {
    return UIScreen.mainScreen().bounds.size.height >= 480
    return currentDeviceSize >= 480
    }

    class func IS_3_5_INCHES_OR_SMALLER() -> Bool {
    return UIScreen.mainScreen().bounds.size.height <= 480
    return currentDeviceSize <= 480
    }

    // MARK: 4 Inch Checks

    class func IS_4_INCHES() -> Bool {
    return UIScreen.mainScreen().bounds.size.height == 568
    return currentDeviceSize == 568
    }

    class func IS_4_INCHES_OR_LARGER() -> Bool {
    return UIScreen.mainScreen().bounds.size.height >= 568
    return currentDeviceSize >= 568
    }

    class func IS_4_INCHES_OR_SMALLER() -> Bool {
    return UIScreen.mainScreen().bounds.size.height <= 568
    return currentDeviceSize <= 568
    }

    // MARK: 4.7 Inch Checks

    class func IS_4_7_INCHES() -> Bool {
    return UIScreen.mainScreen().bounds.size.height == 667
    return currentDeviceSize == 667
    }

    class func IS_4_7_INCHES_OR_LARGER() -> Bool {
    return UIScreen.mainScreen().bounds.size.height >= 667
    return currentDeviceSize >= 667
    }

    class func IS_4_7_INCHES_OR_SMALLER() -> Bool {
    return UIScreen.mainScreen().bounds.size.height <= 667
    return currentDeviceSize <= 667
    }

    // MARK: 5.5 Inch Checks

    class func IS_5_5_INCHES() -> Bool {
    return UIScreen.mainScreen().bounds.size.height == 736
    return currentDeviceSize == 736
    }

    class func IS_5_5_INCHES_OR_LARGER() -> Bool {
    return UIScreen.mainScreen().bounds.size.height >= 736
    return currentDeviceSize >= 736
    }

    class func IS_5_5_INCHES_OR_SMALLER() -> Bool {
    return UIScreen.mainScreen().bounds.size.height <= 736
    return currentDeviceSize <= 736
    }
    }
  6. imkevinxu revised this gist Feb 10, 2015. 1 changed file with 66 additions and 6 deletions.
    72 changes: 66 additions & 6 deletions Device.swift
    Original file line number Diff line number Diff line change
    @@ -11,37 +11,79 @@ import Foundation
    // MARK: - Device Class

    class Device {
    // MARK: Device Version Checks

    // MARK: - Device Version Checks

    // MARK: iOS 5 Checks

    class func IS_OS_5() -> Bool {
    return UIDevice.currentDevice().systemVersion.floatValue >= 5.0
    && UIDevice.currentDevice().systemVersion.floatValue < 6.0
    }

    class func IS_OS_5_OR_LATER() -> Bool {
    return UIDevice.currentDevice().systemVersion.floatValue >= 5.0
    }

    class func IS_OS_5_OR_EARLIER() -> Bool {
    return UIDevice.currentDevice().systemVersion.floatValue < 6.0
    }

    // MARK: iOS 6 Checks

    class func IS_OS_6() -> Bool {
    return UIDevice.currentDevice().systemVersion.floatValue >= 6.0
    && UIDevice.currentDevice().systemVersion.floatValue < 7.0
    }

    class func IS_OS_6_OR_LATER() -> Bool {
    return UIDevice.currentDevice().systemVersion.floatValue >= 6.0
    }

    class func IS_OS_6_OR_EARLIER() -> Bool {
    return UIDevice.currentDevice().systemVersion.floatValue < 7.0
    }

    // MARK: iOS 7 Checks

    class func IS_OS_7() -> Bool {
    return UIDevice.currentDevice().systemVersion.floatValue >= 7.0
    && UIDevice.currentDevice().systemVersion.floatValue < 8.0
    }

    class func IS_OS_7_OR_LATER() -> Bool {
    return UIDevice.currentDevice().systemVersion.floatValue >= 7.0
    }

    class func IS_OS_7_OR_EARLIER() -> Bool {
    return UIDevice.currentDevice().systemVersion.floatValue < 8.0
    }

    // MARK: iOS 8 Checks

    class func IS_OS_8() -> Bool {
    return UIDevice.currentDevice().systemVersion.floatValue >= 7.0
    && UIDevice.currentDevice().systemVersion.floatValue < 8.0
    return UIDevice.currentDevice().systemVersion.floatValue >= 8.0
    && UIDevice.currentDevice().systemVersion.floatValue < 9.0
    }

    class func IS_OS_8_OR_LATER() -> Bool {
    return UIDevice.currentDevice().systemVersion.floatValue >= 8.0
    }

    class func IS_OS_8_OR_EARLIER() -> Bool {
    return UIDevice.currentDevice().systemVersion.floatValue < 9.0
    }

    // MARK: Device Size Checks
    // MARK: - Device Size Checks

    // MARK: Retina Check

    class func IS_RETINA() -> Bool {
    return UIScreen.mainScreen().respondsToSelector("scale")
    }

    // MARK: 3.5 Inch Checks

    class func IS_3_5_INCHES() -> Bool {
    return UIScreen.mainScreen().bounds.size.height == 480
    }
    @@ -50,6 +92,12 @@ class Device {
    return UIScreen.mainScreen().bounds.size.height >= 480
    }

    class func IS_3_5_INCHES_OR_SMALLER() -> Bool {
    return UIScreen.mainScreen().bounds.size.height <= 480
    }

    // MARK: 4 Inch Checks

    class func IS_4_INCHES() -> Bool {
    return UIScreen.mainScreen().bounds.size.height == 568
    }
    @@ -58,6 +106,12 @@ class Device {
    return UIScreen.mainScreen().bounds.size.height >= 568
    }

    class func IS_4_INCHES_OR_SMALLER() -> Bool {
    return UIScreen.mainScreen().bounds.size.height <= 568
    }

    // MARK: 4.7 Inch Checks

    class func IS_4_7_INCHES() -> Bool {
    return UIScreen.mainScreen().bounds.size.height == 667
    }
    @@ -66,6 +120,12 @@ class Device {
    return UIScreen.mainScreen().bounds.size.height >= 667
    }

    class func IS_4_7_INCHES_OR_SMALLER() -> Bool {
    return UIScreen.mainScreen().bounds.size.height <= 667
    }

    // MARK: 5.5 Inch Checks

    class func IS_5_5_INCHES() -> Bool {
    return UIScreen.mainScreen().bounds.size.height == 736
    }
    @@ -74,7 +134,7 @@ class Device {
    return UIScreen.mainScreen().bounds.size.height >= 736
    }

    class func IS_RETINA() -> Bool {
    return UIScreen.mainScreen().respondsToSelector("scale")
    class func IS_5_5_INCHES_OR_SMALLER() -> Bool {
    return UIScreen.mainScreen().bounds.size.height <= 736
    }
    }
  7. imkevinxu created this gist Feb 10, 2015.
    80 changes: 80 additions & 0 deletions Device.swift
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,80 @@
    //
    // Device.swift
    // imHome
    //
    // Created by Kevin Xu on 2/9/15.
    // Copyright (c) 2015 Alpha Labs, Inc. All rights reserved.
    //

    import Foundation

    // MARK: - Device Class

    class Device {
    // MARK: Device Version Checks
    class func IS_OS_5() -> Bool {
    return UIDevice.currentDevice().systemVersion.floatValue >= 5.0
    && UIDevice.currentDevice().systemVersion.floatValue < 6.0
    }
    class func IS_OS_5_OR_LATER() -> Bool {
    return UIDevice.currentDevice().systemVersion.floatValue >= 5.0
    }
    class func IS_OS_6() -> Bool {
    return UIDevice.currentDevice().systemVersion.floatValue >= 6.0
    && UIDevice.currentDevice().systemVersion.floatValue < 7.0
    }
    class func IS_OS_6_OR_LATER() -> Bool {
    return UIDevice.currentDevice().systemVersion.floatValue >= 6.0
    }
    class func IS_OS_7() -> Bool {
    return UIDevice.currentDevice().systemVersion.floatValue >= 7.0
    && UIDevice.currentDevice().systemVersion.floatValue < 8.0
    }
    class func IS_OS_7_OR_LATER() -> Bool {
    return UIDevice.currentDevice().systemVersion.floatValue >= 7.0
    }
    class func IS_OS_8() -> Bool {
    return UIDevice.currentDevice().systemVersion.floatValue >= 7.0
    && UIDevice.currentDevice().systemVersion.floatValue < 8.0
    }
    class func IS_OS_8_OR_LATER() -> Bool {
    return UIDevice.currentDevice().systemVersion.floatValue >= 8.0
    }

    // MARK: Device Size Checks
    class func IS_3_5_INCHES() -> Bool {
    return UIScreen.mainScreen().bounds.size.height == 480
    }

    class func IS_3_5_INCHES_OR_LARGER() -> Bool {
    return UIScreen.mainScreen().bounds.size.height >= 480
    }

    class func IS_4_INCHES() -> Bool {
    return UIScreen.mainScreen().bounds.size.height == 568
    }

    class func IS_4_INCHES_OR_LARGER() -> Bool {
    return UIScreen.mainScreen().bounds.size.height >= 568
    }

    class func IS_4_7_INCHES() -> Bool {
    return UIScreen.mainScreen().bounds.size.height == 667
    }

    class func IS_4_7_INCHES_OR_LARGER() -> Bool {
    return UIScreen.mainScreen().bounds.size.height >= 667
    }

    class func IS_5_5_INCHES() -> Bool {
    return UIScreen.mainScreen().bounds.size.height == 736
    }

    class func IS_5_5_INCHES_OR_LARGER() -> Bool {
    return UIScreen.mainScreen().bounds.size.height >= 736
    }

    class func IS_RETINA() -> Bool {
    return UIScreen.mainScreen().respondsToSelector("scale")
    }
    }