Skip to content

Commit 8a3154b

Browse files
committed
Merge branch 'release/1.0.3'
2 parents ad9cb71 + 7c2622f commit 8a3154b

File tree

8 files changed

+160
-84
lines changed

8 files changed

+160
-84
lines changed

.xcode-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
8.3
1+
8.3.3

Sources/Device.swift

Lines changed: 130 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,18 @@ public enum Device {
4949
case iPhone6s
5050
/// - iPhone6sPlus: All iPhone 6s Plus variants.
5151
case iPhone6sPlus
52-
/// - iPhoneSE: iPhone SE.
52+
/// - iPhoneSE: All iPhone SE variants.
5353
case iPhoneSE
5454
/// - iPhone7: All iPhone 7 variants.
5555
case iPhone7
5656
/// - iPhone7Plus: All iPhone 7 Plus variants.
5757
case iPhone7Plus
58-
58+
/// - iPhone8: All iPhone 8 variants.
59+
case iPhone8
60+
/// - iPhone8Plus: All iPhone 8 Plus variants.
61+
case iPhone8Plus
62+
/// - iPhoneX: All iPhone X variants.
63+
case iPhoneX
5964

6065
/// - iPad2: All iPad 2 variants.
6166
case iPad2
@@ -94,12 +99,17 @@ public enum Device {
9499
/// - appleTV4: Apple TV 4.
95100
case appleTV4
96101

102+
/// - appleTV4K: Apple TV 4K.
103+
case appleTV4K
104+
97105
/// - watch: The original Apple Watch.
98106
case watch
99107
/// - watchSeries1: Apple Watch Series 1.
100108
case watchSeries1
101109
/// - watchSeries2: Apple Watch Series 2.
102110
case watchSeries2
111+
/// - watchSeries3: Apple Watch Series 3.
112+
case watchSeries3
103113

104114
/// - simulator: A simulator for the associated device model.
105115
indirect case simulator(Device)
@@ -109,44 +119,48 @@ public enum Device {
109119

110120
/// All real-device values.
111121
public static let allValues: [Device] = [
112-
.iPhone4S,
113-
.iPhone5,
114-
.iPhone5c,
115-
.iPhone5s,
116-
.iPhone6,
117-
.iPhone6Plus,
118-
.iPhone6s,
119-
.iPhone6sPlus,
120-
.iPhoneSE,
121-
.iPhone7,
122-
.iPhone7Plus,
123-
.iPodTouch5G,
124-
.iPodTouch6G,
125-
.appleTV4,
126-
.watch,
127-
.watchSeries1,
128-
.watchSeries2,
129-
.iPad2,
130-
.iPad3,
131-
.iPad4,
132-
.iPad5,
133-
.iPadAir,
134-
.iPadAir2,
135-
.iPadPro12Inch,
136-
.iPadPro9Inch,
137-
.iPadPro12Inch2G,
138-
.iPadPro10Inch,
139-
.iPadMini,
140-
.iPadMini2,
141-
.iPadMini3,
142-
.iPadMini4,
122+
.iPhone4S,
123+
.iPhone5,
124+
.iPhone5c,
125+
.iPhone5s,
126+
.iPhone6,
127+
.iPhone6Plus,
128+
.iPhone6s,
129+
.iPhone6sPlus,
130+
.iPhoneSE,
131+
.iPhone7,
132+
.iPhone7Plus,
133+
.iPhone8,
134+
.iPhone8Plus,
135+
.iPhoneX,
136+
.iPodTouch5G,
137+
.iPodTouch6G,
138+
.appleTV4,
139+
.appleTV4K,
140+
.watch,
141+
.watchSeries1,
142+
.watchSeries2,
143+
.watchSeries3,
144+
.iPad2,
145+
.iPad3,
146+
.iPad4,
147+
.iPad5,
148+
.iPadAir,
149+
.iPadAir2,
150+
.iPadPro12Inch,
151+
.iPadPro9Inch,
152+
.iPadPro12Inch2G,
153+
.iPadPro10Inch,
154+
.iPadMini,
155+
.iPadMini2,
156+
.iPadMini3,
157+
.iPadMini4,
143158
]
144159

145160
}
146161

147162
public extension Device {
148163

149-
150164
/// Inspects the current device.
151165
public init() {
152166
self = RawDevice(identifier: nil).device!
@@ -158,14 +172,12 @@ public extension Device {
158172
///
159173
/// - Parameter identifier: A device identifier, e.g. "iPhone9,2", "iPad6,11.", "AppleTV5,3".
160174
public init?(identifier: String? = nil) {
161-
guard let thingy = RawDevice(identifier: identifier).device
175+
guard let device = RawDevice(identifier: identifier).device
162176
else {
163177
return nil
164178
}
165-
166-
self = thingy
179+
self = device
167180
}
168-
169181
}
170182

171183
// MARK: - Errors
@@ -194,19 +206,24 @@ public extension Device {
194206
.iPhone6sPlus,
195207
.iPhoneSE,
196208
.iPhone7,
197-
.iPhone7Plus:
209+
.iPhone7Plus,
210+
.iPhone8,
211+
.iPhone8Plus,
212+
.iPhoneX:
198213
return .phone
199214

200215
case .iPodTouch5G,
201216
.iPodTouch6G:
202217
return .pod
203218

204-
case .appleTV4:
219+
case .appleTV4,
220+
.appleTV4K:
205221
return .tv
206222

207223
case .watch,
208224
.watchSeries1,
209-
.watchSeries2:
225+
.watchSeries2,
226+
.watchSeries3:
210227
return .watch
211228

212229
case .iPad2,
@@ -267,6 +284,12 @@ internal extension Device {
267284
return [9.1, 9.3]
268285
case .iPhone7Plus:
269286
return [9.2, 9.4]
287+
case .iPhone8:
288+
return [10.1, 10.4]
289+
case .iPhone8Plus:
290+
return [10.2, 10.5]
291+
case .iPhoneX:
292+
return [10.3, 10.6]
270293

271294
case .iPodTouch5G:
272295
return [5.1]
@@ -275,13 +298,17 @@ internal extension Device {
275298

276299
case .appleTV4:
277300
return [5.3]
301+
case .appleTV4K:
302+
return [6.2]
278303

279304
case .watch:
280305
return [1.1, 1.2]
281306
case .watchSeries1:
282307
return [2.6, 2.7]
283308
case .watchSeries2:
284309
return [2.3, 2.4]
310+
case .watchSeries3:
311+
return [3.1, 3.2, 3.3, 3.4]
285312

286313
case .iPad2:
287314
return [2.1, 2.2, 2.3, 2.4]
@@ -393,6 +420,12 @@ extension Device: MarketingProtocol {
393420
return "iPhone 7"
394421
case .iPhone7Plus:
395422
return "iPhone 7 Plus"
423+
case .iPhone8:
424+
return "iPhone 8"
425+
case .iPhone8Plus:
426+
return "iPhone 8 Plus"
427+
case .iPhoneX:
428+
return "iPhone X"
396429

397430
case .iPad2:
398431
return "iPad 2"
@@ -415,28 +448,32 @@ extension Device: MarketingProtocol {
415448
case .iPadAir2:
416449
return "iPad Air 2"
417450
case .iPadPro12Inch:
418-
return "iPad Pro (12.9 inch)"
451+
return "12.9-inch iPad Pro"
419452
case .iPadPro9Inch:
420-
return "iPad Pro (9.7 inch)"
453+
return "9.7-inch iPad Pro"
421454
case .iPadPro12Inch2G:
422-
return "iPad Pro (12.9 inch) (2nd generation)"
455+
return "12.9-inch iPad Pro (2nd generation)"
423456
case .iPadPro10Inch:
424-
return "iPad Pro (10.5 inch)"
457+
return "10.5-inch iPad Pro"
425458

426459
case .iPodTouch5G:
427460
return "iPod touch (5th generation)"
428461
case .iPodTouch6G:
429462
return "iPod touch (6th generation)"
430463

431464
case .appleTV4:
432-
return "Apple TV 4"
465+
return "Apple TV"
466+
case .appleTV4K:
467+
return "Apple TV 4K"
433468

434469
case .watch:
435470
return "Apple Watch"
436471
case .watchSeries1:
437472
return "Apple Watch Series 1"
438473
case .watchSeries2:
439474
return "Apple Watch Series 2"
475+
case .watchSeries3:
476+
return "Apple Watch Series 3"
440477

441478
case let .simulator(model):
442479
return NSLocalizedString("Simulator (\(model.marketingName))", comment: "Simulator (\(model.marketingName))")
@@ -453,7 +490,6 @@ extension Device: MarketingProtocol {
453490

454491
public extension Device {
455492

456-
457493
/// Returns the display size in inches.
458494
public var displaySize: Display.Size {
459495
return display.size
@@ -463,60 +499,85 @@ public extension Device {
463499
public var display: Display {
464500
switch self {
465501
case .iPhone4S:
466-
return Display(size: .screen3_5Inch, resolution: CGSize(width: 320, height: 480), physicalResolution: CGSize(width: 640, height: 960), renderedResolution: CGSize(width: 640, height: 960), scale: 2.0, density: 326)
502+
return Display(size: .screen3_5Inch, resolution: CGSize(width: 320, height: 480), physicalResolution: CGSize(width: 640, height: 960), renderedResolution: CGSize(width: 640, height: 960), scale: 2.0, density: 326, hasTrueTone: false, colorSpace: .sRGB)
467503

468504
case .iPhone5,
469505
.iPhone5c,
470506
.iPhone5s,
471507
.iPhoneSE,
472508
.iPodTouch5G,
473509
.iPodTouch6G:
474-
return Display(size: .screen4Inch, resolution: CGSize(width: 320, height: 568), physicalResolution: CGSize(width: 640, height: 1136), renderedResolution: CGSize(width: 640, height: 1136), scale: 2.0, density: 326)
510+
return Display(size: .screen4Inch, resolution: CGSize(width: 320, height: 568), physicalResolution: CGSize(width: 640, height: 1136), renderedResolution: CGSize(width: 640, height: 1136), scale: 2.0, density: 326, hasTrueTone: false, colorSpace: .sRGB)
475511

476512
case .iPhone6,
477-
.iPhone6s,
478-
.iPhone7:
479-
return Display(size: .screen4_7Inch, resolution: CGSize(width: 375, height: 667), physicalResolution: CGSize(width: 750, height: 1334), renderedResolution: CGSize(width: 750, height: 1334), scale: 2.0, density: 326)
513+
.iPhone6s:
514+
return Display(size: .screen4_7Inch, resolution: CGSize(width: 375, height: 667), physicalResolution: CGSize(width: 750, height: 1334), renderedResolution: CGSize(width: 750, height: 1334), scale: 2.0, density: 326, hasTrueTone: false, colorSpace: .sRGB)
515+
516+
case .iPhone7:
517+
return Display(size: .screen4_7Inch, resolution: CGSize(width: 375, height: 667), physicalResolution: CGSize(width: 750, height: 1334), renderedResolution: CGSize(width: 750, height: 1334), scale: 2.0, density: 326, hasTrueTone: false, colorSpace: .p3)
518+
519+
case .iPhone8:
520+
return Display(size: .screen4_7Inch, resolution: CGSize(width: 375, height: 667), physicalResolution: CGSize(width: 750, height: 1334), renderedResolution: CGSize(width: 750, height: 1334), scale: 2.0, density: 326, hasTrueTone: true, colorSpace: .p3)
480521

481522
case .iPhone6Plus,
482-
.iPhone6sPlus,
483-
.iPhone7Plus:
484-
return Display(size: .screen5_5Inch, resolution: CGSize(width: 414, height: 736), physicalResolution: CGSize(width: 1080, height: 1920), renderedResolution: CGSize(width: 1242, height: 2208), scale: 3.0, density: 401)
523+
.iPhone6sPlus:
524+
return Display(size: .screen5_5Inch, resolution: CGSize(width: 414, height: 736), physicalResolution: CGSize(width: 1080, height: 1920), renderedResolution: CGSize(width: 1242, height: 2208), scale: 3.0, density: 401, hasTrueTone: false, colorSpace: .sRGB)
525+
526+
case .iPhone7Plus:
527+
return Display(size: .screen5_5Inch, resolution: CGSize(width: 414, height: 736), physicalResolution: CGSize(width: 1080, height: 1920), renderedResolution: CGSize(width: 1242, height: 2208), scale: 3.0, density: 401, hasTrueTone: false, colorSpace: .p3)
528+
529+
case .iPhone8Plus:
530+
return Display(size: .screen5_5Inch, resolution: CGSize(width: 414, height: 736), physicalResolution: CGSize(width: 1080, height: 1920), renderedResolution: CGSize(width: 1242, height: 2208), scale: 3.0, density: 401, hasTrueTone: true, colorSpace: .p3)
531+
532+
case .iPhoneX:
533+
return Display(size: .screen5_8Inch, resolution: CGSize(width: 375, height: 812), physicalResolution: CGSize(width: 2436, height: 1125), renderedResolution: CGSize(width: 1242, height: 2208), scale: 3.0, density: 458, hasTrueTone: true, colorSpace: .p3)
485534

486535
case .appleTV4:
487-
return Display(size: .notApplicable, resolution: CGSize(width: 1920, height: 1080), physicalResolution: CGSize(width: 1920, height: 1080), renderedResolution: CGSize(width: 1920, height: 1080), scale: 1.0, density: 0)
536+
return Display(size: .notApplicable, resolution: CGSize(width: 1920, height: 1080), physicalResolution: CGSize(width: 1920, height: 1080), renderedResolution: CGSize(width: 1920, height: 1080), scale: 1.0, density: 0, hasTrueTone: false, colorSpace: .sRGB)
537+
538+
case .appleTV4K:
539+
return Display(size: .notApplicable, resolution: CGSize(width: 3840, height: 2160), physicalResolution: CGSize(width: 3840, height: 2160), renderedResolution: CGSize(width: 3840, height: 2160), scale: 1.0, density: 0, hasTrueTone: false, colorSpace: .sRGB)
488540

489541
case .iPad2:
490-
return Display(size: .screen9_7Inch, resolution: CGSize(width: 1024, height: 768), physicalResolution: CGSize(width: 1024, height: 768), renderedResolution: CGSize(width: 1024, height: 768), scale: 1.0, density: 132)
542+
return Display(size: .screen9_7Inch, resolution: CGSize(width: 1024, height: 768), physicalResolution: CGSize(width: 1024, height: 768), renderedResolution: CGSize(width: 1024, height: 768), scale: 1.0, density: 132, hasTrueTone: false, colorSpace: .sRGB)
491543

492544
case .iPad3,
493545
.iPad4,
494546
.iPad5,
495547
.iPadAir,
496-
.iPadAir2,
497-
.iPadPro9Inch:
498-
return Display(size: .screen9_7Inch, resolution: CGSize(width: 1024, height: 768), physicalResolution: CGSize(width: 2048, height: 1536), renderedResolution: CGSize(width: 2048, height: 1536), scale: 2.0, density: 264)
499-
case .iPadPro12Inch,
500-
.iPadPro12Inch2G:
501-
return Display(size: .screen12_9Inch, resolution: CGSize(width: 1366, height: 1024), physicalResolution: CGSize(width: 2732, height: 2048), renderedResolution: CGSize(width: 2732, height: 2048), scale: 2.0, density: 264)
548+
.iPadAir2:
549+
return Display(size: .screen9_7Inch, resolution: CGSize(width: 1024, height: 768), physicalResolution: CGSize(width: 2048, height: 1536), renderedResolution: CGSize(width: 2048, height: 1536), scale: 2.0, density: 264, hasTrueTone: false, colorSpace: .sRGB)
550+
551+
case .iPadPro12Inch:
552+
return Display(size: .screen12_9Inch, resolution: CGSize(width: 1366, height: 1024), physicalResolution: CGSize(width: 2732, height: 2048), renderedResolution: CGSize(width: 2732, height: 2048), scale: 2.0, density: 264, hasTrueTone: false, colorSpace: .sRGB)
553+
554+
case .iPadPro9Inch:
555+
return Display(size: .screen9_7Inch, resolution: CGSize(width: 1024, height: 768), physicalResolution: CGSize(width: 2048, height: 1536), renderedResolution: CGSize(width: 2048, height: 1536), scale: 2.0, density: 264, hasTrueTone: true, colorSpace: .p3)
556+
557+
case .iPadPro12Inch2G:
558+
return Display(size: .screen12_9Inch, resolution: CGSize(width: 1366, height: 1024), physicalResolution: CGSize(width: 2732, height: 2048), renderedResolution: CGSize(width: 2732, height: 2048), scale: 2.0, density: 264, hasTrueTone: true, colorSpace: .p3)
559+
502560
case .iPadPro10Inch:
503-
return Display(size: .screen12_9Inch, resolution: CGSize(width: 1112, height: 834), physicalResolution: CGSize(width: 2224, height: 1668), renderedResolution: CGSize(width: 2224, height: 1668), scale: 2.0, density: 264)
561+
return Display(size: .screen12_9Inch, resolution: CGSize(width: 1112, height: 834), physicalResolution: CGSize(width: 2224, height: 1668), renderedResolution: CGSize(width: 2224, height: 1668), scale: 2.0, density: 264, hasTrueTone: true, colorSpace: .p3)
562+
504563
case .iPadMini:
505-
return Display(size: .screen7_9Inch, resolution: CGSize(width: 1024, height: 768), physicalResolution: CGSize(width: 1024, height: 768), renderedResolution: CGSize(width: 1024, height: 768), scale: 1.0, density: 163)
564+
return Display(size: .screen7_9Inch, resolution: CGSize(width: 1024, height: 768), physicalResolution: CGSize(width: 1024, height: 768), renderedResolution: CGSize(width: 1024, height: 768), scale: 1.0, density: 163, hasTrueTone: false, colorSpace: .sRGB)
565+
506566
case .iPadMini2,
507567
.iPadMini3,
508568
.iPadMini4:
509-
return Display(size: .screen7_9Inch, resolution: CGSize(width: 1024, height: 768), physicalResolution: CGSize(width: 2048, height: 1536), renderedResolution: CGSize(width: 2048, height: 1536), scale: 2.0, density: 326)
569+
return Display(size: .screen7_9Inch, resolution: CGSize(width: 1024, height: 768), physicalResolution: CGSize(width: 2048, height: 1536), renderedResolution: CGSize(width: 2048, height: 1536), scale: 2.0, density: 326, hasTrueTone: false, colorSpace: .sRGB)
510570

511571
case let .simulator(model):
512572
return model.display
513573

514-
// FIXME: Add a way to inspect the Apple Watch displays.
574+
// FIXME: Add a way to inspect the Apple Watch displays.
515575
case .unknown(_),
516576
.watch,
517577
.watchSeries1,
518-
.watchSeries2:
519-
return Display(size: .notApplicable, resolution: CGSize.zero, physicalResolution: CGSize.zero, renderedResolution: CGSize.zero, scale: 0, density: 0)
578+
.watchSeries2,
579+
.watchSeries3:
580+
return Display(size: .notApplicable, resolution: CGSize.zero, physicalResolution: CGSize.zero, renderedResolution: CGSize.zero, scale: 0, density: 0, hasTrueTone: false, colorSpace: .sRGB)
520581
}
521582
}
522583

@@ -526,7 +587,6 @@ public extension Device {
526587

527588
public extension Device {
528589

529-
530590
/// Checks if the current device is the same as the compared model.
531591
///
532592
/// - Parameter to: A model to compare the current device against.

0 commit comments

Comments
 (0)