1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
| extension UIDevice { var modelType: IphoneType { var systemInfo = utsname() uname(&systemInfo) let machineMirror = Mirror(reflecting: systemInfo.machine) let identifier = machineMirror.children.reduce("") { identifier, element in guard let value = element.value as? Int8, value != 0 else { return identifier } return identifier + String(UnicodeScalar(UInt8(value))) }
switch identifier { case "iPhone3,1", "iPhone3,2", "iPhone3,3": return .iPhone4 case "iPhone4,1": return .iPhone4s case "iPhone5,1", "iPhone5,2": return .iPhone5 case "iPhone5,3", "iPhone5,4": return .iPhone5c case "iPhone6,1", "iPhone6,2": return .iPhone5s case "iPhone7,2": return .iPhone6 case "iPhone7,1": return .iPhone6_Plus case "iPhone8,1": return .iPhone6s case "iPhone8,2": return .iPhone6s_Plus case "iPhone8,4": return .iPhoneSE case "iPhone9,1", "iPhone9,3": return .iPhone7 case "iPhone9,2", "iPhone9,4": return .iPhone7_Plus case "iPhone10,1": return .iPhone8 case "iPhone10,2", "iPhone10,5": return .iPhone8_Plus case "iPhone10,3", "iPhone10,6": return .iPhoneX case "iPhone11,8": return .iPhoneXR case "iPhone11,2": return .iPhoneXS case "iPhone11,6", "iPhone11,4": return .iPhoneXS_Max case "i386", "x86_64": return .similator default: return . other } } }
enum IphoneType: String { case other case simulator case iPhone4 case iPhone4s case iPhone5 case iPhone5c case iPhone5s case iPhone6 case iPhone6_Plus case iPhone6s case iPhone6s_Plus case iPhoneSE case iPhone7 case iPhone7_Plus case iPhone8 case iPhone8_Plus case iPhoneX case iPhoneXR case iPhoneXS case iPhoneXS_Max }
|