Created
November 11, 2019 06:36
-
-
Save Achyut-Sagar/2fed1de090a193cb848caf2d84dc4167 to your computer and use it in GitHub Desktop.
iOS Device Detector
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 Foundation | |
| import UIKit | |
| extension UIDevice{ | |
| var deviceModel : DeviceFamily{ | |
| switch UIScreen.main.nativeBounds.height { | |
| case 960: | |
| return .iPhone_4 | |
| case 1136: | |
| return .iPhone_5 | |
| case 1334: | |
| return .iPhone_6_7_8 | |
| case 1792: | |
| return .iPhone_XR | |
| case 1920, 2208: | |
| return .iPhone_6P_7P_8P | |
| case 2436: | |
| return .iPhone_X | |
| case 2688: | |
| return .iPhone_XsMax | |
| default: | |
| return .unknown | |
| } | |
| } | |
| } | |
| enum DeviceFamily{ | |
| case iPhone_4 // 3.5 inch | |
| case iPhone_5 // 4 inch | |
| case iPhone_6_7_8 // 4.7 inch | |
| case iPhone_6P_7P_8P // 5.5 inch | |
| case iPhone_X // 5.8 inch | |
| case iPhone_XR // 6.1 inch | |
| case iPhone_XsMax // 6.5 inch | |
| case unknown // alien device | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment