[Swift] Get devices model range

Here a simple and easy memo for getting the iPhones devices models .

I’ve used the  property, available from iOS 8+:

var nativeBounds:  { get }

This rectangle is based on the device in a -up . This value does not change as the device rotates.

https://developer.apple.com/documentation/uikit/uiscreen/1617810-nativebounds 

Code:
// Device range

enum  {
    case iPhone_4
    case iPhone_5_SE
    case iPhone_6s_7_8
    case iPhone_6sp_7p_8p
    case iPhone_X
    case Unknown
}

Now you can get your device range. For any use you want.

// get device range by native size

static func deviceRange() -> DeviceType {
    if UIScreen.main.nativeBounds. == 480 {
        return .iPhone_4
    }

    if UIScreen.main.nativeBounds.height == 1136 {
        return .iPhone_5_SE
    }

    if UIScreen.main.nativeBounds.height == 1334 {
        return .iPhone_6s_7_8
    }

    if UIScreen.main.nativeBounds.height == 2208 {
        return .iPhone_6sp_7p_8p
    }

    if UIScreen.main.nativeBounds.height == 2436 {
        return .iPhone_X
    }

     return .Unknown
}
Example:
if DeviceUtils.deviceRange() == .iPhone_4 {
    exit(0) // lol
}

 

done.