[Swift] Get devices model range

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

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

var nativeBounds:  { get }

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

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

Code:
// Device range

enum DeviceType {
    case _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 

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 {
     // lol
}

 

done.