Skip to content

Commit 04d2be7

Browse files
author
Felipe Augusto
committed
Merge branch 'new-iphones' into updates-and-fixes
2 parents 746a444 + 34e5cfc commit 04d2be7

File tree

4 files changed

+49
-58
lines changed

4 files changed

+49
-58
lines changed

AssistantKit/Classes/OS.swift

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ extension Device {
2020
public static var os9 = OSVersion("9")
2121
public static var os10 = OSVersion("10")
2222
public static var os11 = OSVersion("11")
23+
public static var os12 = OSVersion("12")
2324

2425
/// Struct to work with OS version
2526
public struct OSVersion {

AssistantKit/Classes/Screen.swift

+8-3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ public enum Screen: CGFloat {
2525
case inches_4_7 = 4.7
2626
case inches_5_5 = 5.5
2727
case inches_5_8 = 5.8 // iPhone X diagonal
28+
case inches_6_1 = 6.1
29+
case inches_6_5 = 6.5
2830
case inches_7_9 = 7.9
2931
case inches_9_7 = 9.7
3032
case inches_12_9 = 12.9
@@ -38,7 +40,7 @@ public enum Screen: CGFloat {
3840
case .inches_4_7:
3941
return .small
4042

41-
case .inches_5_5, .inches_7_9, .inches_5_8:
43+
case .inches_5_5, .inches_7_9, .inches_5_8, .inches_6_1, .inches_6_5:
4244
return .medium
4345

4446
case .inches_9_7, .inches_12_9:
@@ -139,7 +141,7 @@ public func <(lhs: Scale, rhs: Scale) -> Bool {
139141

140142
public func >(lhs: Scale, rhs: Scale) -> Bool {
141143
guard lhs.rawValue > 0 && rhs.rawValue > 0 else { return false }
142-
return lhs.rawValue < rhs.rawValue
144+
return lhs.rawValue > rhs.rawValue
143145
}
144146

145147
public func <=(lhs: Scale, rhs: Scale) -> Bool {
@@ -178,6 +180,9 @@ extension Device {
178180
case 812:
179181
return .inches_5_8
180182

183+
case 896:
184+
return ( scale == .x3 ? .inches_6_5 : .inches_6_1 )
185+
181186
case 1024:
182187
switch version {
183188
case .padMini, .padMini2, .padMini3, .padMini4:
@@ -252,7 +257,7 @@ extension Device {
252257
case .big:
253258
return big
254259

255-
default:
260+
case .unknown:
256261
return small
257262
}
258263
}

AssistantKit/Classes/Type.swift

+21-42
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ public enum Version: String {
4040
case phone8
4141
case phone8Plus
4242
case phoneX
43+
case phoneXS
44+
case phoneXSMax
45+
case phoneXR
4346

4447
case pad1
4548
case pad2
@@ -97,8 +100,15 @@ public enum Version: String {
97100
.phone8Plus:
98101
return .inches_5_5
99102

100-
case .phoneX:
101-
return.inches_5_8
103+
case .phoneX,
104+
.phoneXS:
105+
return .inches_5_8
106+
107+
case .phoneXR:
108+
return .inches_6_1
109+
110+
case .phoneXSMax:
111+
return .inches_6_5
102112

103113
case .padMini,
104114
.padMini2,
@@ -117,7 +127,7 @@ public enum Version: String {
117127
case .padPro:
118128
return .inches_12_9
119129

120-
default:
130+
case .unknown, .simulator:
121131
return .unknown
122132
}
123133
}
@@ -132,8 +142,7 @@ extension Device {
132142
uname(&systemInfo)
133143

134144
if let info = NSString(bytes: &systemInfo.machine, length: Int(_SYS_NAMELEN), encoding: String.Encoding.ascii.rawValue),
135-
let code = String(validatingUTF8: info.utf8String!)
136-
{
145+
let code = String(validatingUTF8: info.utf8String!) {
137146
return code
138147
}
139148

@@ -145,59 +154,29 @@ extension Device {
145154
/// - seealso: Type
146155
static public var type: Type {
147156
let versionCode = Device.versionCode
148-
149-
switch versionCode {
150-
case "iPhone3,1", "iPhone3,2", "iPhone3,3",
151-
"iPhone4,1", "iPhone4,2", "iPhone4,3",
152-
"iPhone5,1", "iPhone5,2",
153-
"iPhone5,3", "iPhone5,4",
154-
"iPhone6,1", "iPhone6,2",
155-
"iPhone7,2", "iPhone7,1",
156-
"iPhone8,1", "iPhone8,2", "iPhone8,4",
157-
"iPhone9,1", "iPhone9,2", "iPhone9,3", "iPhone9,4",
158-
"iPhone10,1", "iPhone10,2", "iPhone10,3", "iPhone10,4", "iPhone10,5", "iPhone10,6":
157+
if versionCode.starts(with: "iPhone") {
159158
return .phone
160-
161-
case "iPad1,1",
162-
"iPad2,1", "iPad2,2", "iPad2,3", "iPad2,4",
163-
"iPad3,1", "iPad3,2", "iPad3,3",
164-
"iPad3,4", "iPad3,5", "iPad3,6",
165-
"iPad4,1", "iPad4,2", "iPad4,3",
166-
"iPad5,3", "iPad5,4",
167-
"iPad2,5", "iPad2,6", "iPad2,7",
168-
"iPad4,4", "iPad4,5", "iPad4,6",
169-
"iPad4,7", "iPad4,8", "iPad4,9",
170-
"iPad5,1", "iPad5,2",
171-
"iPad6,3", "iPad6,4", "iPad6,7", "iPad6,8":
159+
} else if versionCode.starts(with: "iPad") {
172160
return .pad
173-
174-
case "iPod1,1",
175-
"iPod2,1",
176-
"iPod3,1",
177-
"iPod4,1",
178-
"iPod5,1",
179-
"iPod7,1":
161+
} else if versionCode.starts(with: "iPod") {
180162
return .pod
181-
182-
case "i386", "x86_64":
163+
} else if versionCode == "i386" || versionCode == "x86_64" {
183164
return .simulator
184-
185-
default:
186-
return .unknown
187165
}
166+
return .unknown
188167
}
189168

190169
/// Return `true` for iPad-s
191170
static public var isPad: Bool {
192171
return ( UIDevice.current.userInterfaceIdiom == .pad )
193172
}
194173

195-
/// Return `true` for iPahone-s
174+
/// Return `true` for iPhone-s
196175
static public var isPhone: Bool {
197176
return !isPad
198177
}
199178

200-
/// Return `true` for iPahoneX
179+
/// Return `true` for iPhoneX
201180
static public var isPhoneX: Bool {
202181
return isPhone && screen == .inches_5_8
203182
}

Example/AssistantKit/ViewController.swift

+19-13
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,9 @@ class ViewController: UIViewController {
162162
case .phone8: print("iPhone 8")
163163
case .phone8Plus: print("iPhone 8 Plus")
164164
case .phoneX: print("iPhone X")
165+
case .phoneXS: print("iPhone XS")
166+
case .phoneXSMax: print("iPhone XS Max")
167+
case .phoneXR: print("iPhone X")
165168

166169
case .pad1: print("iPad 1")
167170
case .pad2: print("iPad 2")
@@ -184,27 +187,30 @@ class ViewController: UIViewController {
184187

185188
case .simulator: print("Simulator")
186189

187-
default: print("Unknown device")
190+
case .unknown: print("Unknown device")
188191
}
189192

190193
let screen = Device.screen
191194
switch screen {
192-
case .inches_3_5: print("3.5 inches")
193-
case .inches_4_0: print("4.0 inches")
194-
case .inches_4_7: print("4.7 inches")
195-
case .inches_5_5: print("5.5 inches")
196-
case .inches_7_9: print("7.9 inches")
197-
case .inches_9_7: print("9.7 inches")
198-
case .inches_12_9: print("12.9 inches")
199-
default: print("Other display")
195+
case .inches_3_5: print("3.5 inches")
196+
case .inches_4_0: print("4.0 inches")
197+
case .inches_4_7: print("4.7 inches")
198+
case .inches_5_5: print("5.5 inches")
199+
case .inches_5_8: print("5.8 inches")
200+
case .inches_6_1: print("6.1 inches")
201+
case .inches_6_5: print("6.5 inches")
202+
case .inches_7_9: print("7.9 inches")
203+
case .inches_9_7: print("9.7 inches")
204+
case .inches_12_9: print("12.9 inches")
205+
case .unknown: print("Other display")
200206
}
201207

202208
let scale = Device.scale
203209
switch scale {
204-
case .x1: print("Not retina")
205-
case .x2: print("Retina 2X")
206-
case .x3: print("Retina 3X")
207-
default: print("Unknown scale")
210+
case .x1: print("Not retina")
211+
case .x2: print("Retina 2X")
212+
case .x3: print("Retina 3X")
213+
case .unknown: print("Unknown scale")
208214
}
209215

210216
let size = Device.size(phone: 13, pad: 15)

0 commit comments

Comments
 (0)