@@ -20,8 +20,7 @@ public enum Device: String, CaseIterable, CustomStringConvertible {
2020 case iPad7thGen = " iPad (7th generation) "
2121 case iPadPro11inch = " iPad Pro (11-inch) "
2222 case iPadPro12·9inch3rdGen = " iPad Pro (12.9-inch) (3nd generation) "
23- // 2020-01-26 sas: this one failed to launch the preview for me:
24- // case iPadMini5thGen = "iPad mini (5th generation)"
23+ case iPadMini5thGen = " iPad mini (5th generation) "
2524 case iPadAir3rdGen = " iPad Air (3rd generation) "
2625
2726 case iPhone6s = " iPhone 6s "
@@ -50,7 +49,7 @@ public enum Device: String, CaseIterable, CustomStringConvertible {
5049
5150 case appleTV4K = " Apple TV 4K "
5251
53- public var previewDevice : PreviewDevice { PreviewDevice ( stringLiteral : rawValue ) }
52+
5453 public static var iPads : [ Device ] { allCases. filter { $0. rawValue. hasPrefix ( " iPad " ) } }
5554 public static var iPhones : [ Device ] { allCases. filter { $0. rawValue. hasPrefix ( " iPhone " ) } }
5655 public static var watches : [ Device ] { allCases. filter { $0. rawValue. hasPrefix ( " Apple Watch " ) } }
@@ -63,6 +62,35 @@ public enum Device: String, CaseIterable, CustomStringConvertible {
6362 }
6463 return rawValue
6564 }
65+
66+ public var previewDevice : PreviewDevice {
67+ let identifier = self . modelNumber ?? rawValue
68+ return PreviewDevice ( stringLiteral: identifier)
69+ }
70+
71+ //Some devices don't seem to launch reliably by name - but model number works
72+ //Keep private as this is an incomplete list
73+ //Model numbers from https://everyi.com/by-identifier/ipod-iphone-ipad-specs-by-model-identifier.html
74+ //(with a bit of trial and error)
75+ private var modelNumber : String ? {
76+ switch self {
77+ case . iPadPro12·9inch:
78+ return " iPad6,8 "
79+ case . iPadPro12·9inch2ndGen:
80+ return " iPad7,1 "
81+ case . iPadPro12·9inch3rdGen:
82+ return " iPad8,5 "
83+ case . iPadPro11inch:
84+ return " iPad8,1 "
85+ case . iPadMini5thGen:
86+ return " iPad11,1 "
87+ case . iPhone11ProMax:
88+ return " iPhone12,5 "
89+
90+ default :
91+ return nil
92+ }
93+ }
6694}
6795
6896
0 commit comments