Skip to content

Instantly share code, notes, and snippets.

@romanfurman6
Last active September 19, 2019 12:47
Show Gist options
  • Save romanfurman6/df0b9e4c09333f370631c32e796a57fe to your computer and use it in GitHub Desktop.
Save romanfurman6/df0b9e4c09333f370631c32e796a57fe to your computer and use it in GitHub Desktop.
UIDevice+Type
import UIKit
extension UIDevice {
// swiftlint:disable identifier_name
enum DeviceType {
case iPhone5s_Se
case iPhone6_7_8
case iPhone6_7_8Plus
case iPhoneX_Xs
case iPhoneXPlus_Xr_XsMax
case unrecognized
}
// swiftlint:enable identifier_name
var type: DeviceType {
// UIScreen.main.bounds.height & UIScreen.main.bounds.width
// Can return inverted values related to device orientation
let bounds = UIScreen.main.bounds
let height = max(bounds.height, bounds.width)
switch height {
case 568.0:
return .iPhone5s_Se
case 667.0:
return .iPhone6_7_8
case 736.0:
return .iPhone6_7_8Plus
case 812.0:
return .iPhoneX_Xs
case 896.0:
return .iPhoneXPlus_Xr_XsMax
default:
return .unrecognized
}
}
// swiftlint:disable:next identifier_name
var isIphone5s_Se: Bool {
return type == .iPhone5s_Se
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment