Skip to content

Commit 4941061

Browse files
Almost done….
1 parent 7a5b362 commit 4941061

25 files changed

+801
-413
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import Foundation
2+
3+
public extension DeviceModel {
4+
var architecture: String? {
5+
switch self {
6+
case .iPod(let model):
7+
return model.processor.architecture
8+
case .iPhone(let model):
9+
return model.processor.architecture
10+
case .iPad(let model):
11+
return model.processor.architecture
12+
case .appleWatch(let model):
13+
return model.processor.architecture
14+
case .appleTV(let model):
15+
return model.processor.architecture
16+
case .mac(let model):
17+
return model.processor.architecture
18+
case .macCatalyst:
19+
return "arm64"
20+
case .macDesignedForIpad:
21+
return "arm64"
22+
case .unknown(_):
23+
return nil
24+
case .simulator(_, let arch):
25+
return arch
26+
}
27+
}
28+
}

Sources/DeviceIdentificator/DeviceModel+RawRepresentable.swift renamed to Sources/DeviceIdentificator/DeviceModel+DeviceIdentifier.swift

Lines changed: 43 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,68 +4,84 @@ import Foundation
44
#endif
55

66
public extension DeviceModel {
7-
// swiftlint:disable:next function_body_length cyclomatic_complexity
8-
init?(rawValue: String) {
9-
if let mac = MacModel(rawValue: rawValue) {
7+
init(deviceIdentifier: String) {
8+
if let mac = IPodModel(rawValue: deviceIdentifier) {
9+
self = .iPod(mac)
10+
return
11+
}
12+
if let mac = IPhoneModel(rawValue: deviceIdentifier) {
13+
self = .iPhone(mac)
14+
return
15+
}
16+
if let mac = IPadModel(rawValue: deviceIdentifier) {
17+
self = .iPad(mac)
18+
return
19+
}
20+
if let mac = AppleWatchModel(rawValue: deviceIdentifier) {
21+
self = .appleWatch(mac)
22+
return
23+
}
24+
if let mac = AppleTVModel(rawValue: deviceIdentifier) {
25+
self = .appleTV(mac)
26+
return
27+
}
28+
if let mac = MacModel(rawValue: deviceIdentifier) {
1029
self = .mac(mac)
1130
return
1231
}
1332

14-
switch rawValue {
15-
33+
switch deviceIdentifier {
34+
1635
#if targetEnvironment(macCatalyst) || os(iOS)
1736
case "arm64" where ProcessInfo.processInfo.isiOSAppOnMac:
1837
self = .macCatalyst
19-
38+
2039
case "arm64" where ProcessInfo.processInfo.isMacCatalystApp:
2140
self = .macDesignedForIpad
2241
#endif
23-
42+
2443
// Simulator
2544
case "i386", "x86_64", "arm64":
2645
let simulatorIdentifierValue = ProcessInfo().environment["SIMULATOR_MODEL_IDENTIFIER"] ?? "Unknown"
27-
let simulatorModel = DeviceModel(rawValue: simulatorIdentifierValue) ??
28-
.unknown(model: simulatorIdentifierValue)
29-
#if os(iOS)
30-
let smallerScreen = UIScreen.main.bounds.size.width < 768
31-
self = smallerScreen ?
32-
.simulator(simulatorModel, arch: rawValue) :
33-
.simulator(simulatorModel, arch: rawValue)
34-
#elseif os(tvOS)
35-
self = .appleTVSimulator(simulatorModel, arch: rawValue)
36-
#elseif os(watchOS)
37-
self = .watchSimulator(simulatorModel, arch: rawValue)
38-
#else
39-
self = .unknown(model: rawValue)
40-
#endif
46+
let simulatorModel = DeviceModel(deviceIdentifier: simulatorIdentifierValue)
47+
self = .simulator(simulatorModel, arch: deviceIdentifier)
4148

4249
default:
43-
return nil
50+
self = .unknown(model: deviceIdentifier)
4451
}
4552
}
46-
47-
var rawValue: String {
53+
54+
var deviceIdentifier: String? {
4855
switch self {
4956
case .iPod(let model):
5057
return model.rawValue
58+
5159
case .iPhone(let model):
5260
return model.rawValue
61+
5362
case .iPad(let model):
5463
return model.rawValue
64+
5565
case .appleWatch(let model):
5666
return model.rawValue
67+
5768
case .appleTV(let model):
5869
return model.rawValue
70+
5971
case .mac(let model):
6072
return model.rawValue
73+
6174
case .macCatalyst:
62-
return ""
75+
return nil
76+
6377
case .macDesignedForIpad:
64-
return ""
78+
return nil
79+
6580
case .unknown(model: let model):
6681
return model
82+
6783
case .simulator(let model, _):
68-
return model.rawValue
84+
return model.deviceIdentifier
6985
}
7086
}
7187
}

Sources/DeviceIdentificator/DeviceModel+Name.swift

Lines changed: 1 addition & 150 deletions
Original file line numberDiff line numberDiff line change
@@ -22,156 +22,7 @@ public extension DeviceModel {
2222
case .unknown(model: let model):
2323
return "Unknown device: \(model)"
2424
case .simulator(let model, let arch):
25-
return "Simulator \(model.name) @ \(arch)"
25+
return "Simulator of \(model.name) @ \(arch)"
2626
}
27-
/*
28-
switch self {
29-
30-
// iPhones
31-
case .iPhone1G: return "iPhone 1G"
32-
case .iPhone3G: return "iPhone 3G"
33-
case .iPhone3GS: return "iPhone 3GS"
34-
case .iPhone4: return "iPhone 4"
35-
case .iPhone4S: return "iPhone 4S"
36-
case .iPhone5: return "iPhone 5"
37-
case .iPhone5C: return "iPhone 5C"
38-
case .iPhone5S: return "iPhone 5S"
39-
case .iPhone6: return "iPhone 6"
40-
case .iPhone6Plus: return "iPhone 6 Plus"
41-
case .iPhone6S: return "iPhone 6S"
42-
case .iPhone6SPlus: return "iPhone 6S Plus"
43-
case .iPhoneSE: return "iPhone SE"
44-
case .iPhone7: return "iPhone 7"
45-
case .iPhone7Plus: return "iPhone 7 Plus"
46-
case .iPhone8: return "iPhone 8"
47-
case .iPhone8Plus: return "iPhone 8 Plus"
48-
case .iPhoneX: return "iPhone X"
49-
case .iPhoneXR: return "iPhone XR"
50-
case .iPhoneXS: return "iPhone XS"
51-
case .iPhoneXSMax: return "iPhone XS Max"
52-
case .iPhone11: return "iPhone 11"
53-
case .iPhone11Pro: return "iPhone 11 Pro"
54-
case .iPhone11ProMax: return "iPhone 11 Pro Max"
55-
case .iPhoneSE2G: return "iPhone SE 2G"
56-
case .iPhone12Mini: return "iPhone 12 Mini"
57-
case .iPhone12: return "iPhone 12"
58-
case .iPhone12Pro: return "iPhone 12 Pro"
59-
case .iPhone12ProMax: return "iPhone 12 Pro Max"
60-
case .iPhone13Pro: return "iPhone 13 Pro"
61-
case .iPhone13ProMax: return "iPhone 13 Pro Max"
62-
case .iPhone13Mini: return "iPhone 13 Mini"
63-
case .iPhone13: return "iPhone 13"
64-
case .iPhoneSE3G: return "iPhone SE 3G"
65-
case .iPhone14: return "iPhone 14"
66-
case .iPhone14Plus: return "iPhone 14 Plus"
67-
case .iPhone14Pro: return "iPhone 14 Pro"
68-
case .iPhone14ProMax: return "iPhone 14 Pro Max"
69-
case .iPhone15: return "iPhone 15"
70-
case .iPhone15Plus: return "iPhone 15 Plus"
71-
case .iPhone15Pro: return "iPhone 15 Pro"
72-
case .iPhone15ProMax: return "iPhone 15 Pro Max"
73-
74-
// iPods Touch
75-
case .iPodTouch1G: return "iPod touch 1G"
76-
case .iPodTouch2G: return "iPod touch 2G"
77-
case .iPodTouch3G: return "iPod touch 3G"
78-
case .iPodTouch4G: return "iPod touch 4G"
79-
case .iPodTouch5G: return "iPod touch 5G"
80-
case .iPodTouch6G: return "iPod touch 6G"
81-
case .iPodTouch7G: return "iPod touch 7G"
82-
83-
// iPads Regular
84-
case .iPad1G: return "iPad 1G"
85-
case .iPad2G: return "iPad 2G"
86-
case .iPad3G: return "iPad 3G"
87-
case .iPad4G: return "iPad 4G"
88-
case .iPad5G: return "iPad 5G"
89-
case .iPad6G: return "iPad 6G"
90-
case .iPad7G: return "iPad 7G"
91-
case .iPad8G: return "iPad 8G"
92-
case .iPad9G: return "iPad 9G"
93-
case .iPad10G: return "iPad 10G"
94-
95-
// iPads Mini
96-
case .iPadMini1: return "iPad Mini"
97-
case .iPadMini2: return "iPad Mini 2"
98-
case .iPadMini3: return "iPad Mini 3"
99-
case .iPadMini4: return "iPad Mini 4"
100-
case .iPadMini5: return "iPad Mini 5"
101-
case .iPadMini6: return "iPad Mini 6"
102-
103-
// iPads Air
104-
case .iPadAir1G: return "iPad Air"
105-
case .iPadAir2G: return "iPad Air 2"
106-
case .iPadAir3G: return "iPad Air 3"
107-
case .iPadAir4G: return "iPad Air 4"
108-
case .iPadAir5G: return "iPad Air 5"
109-
110-
// iPads Pro
111-
case .iPadPro9d7inch1G: return "iPad Pro 9.7-Inch 1G"
112-
case .iPadPro10d5inch1G: return "iPad Pro 10.5-Inch 1G"
113-
case .iPadPro11inch: return "iPad Pro 11-Inch"
114-
case .iPadPro11inch2G: return "iPad Pro 11-Inch 2G"
115-
case .iPadPro11inch3G: return "iPad Pro 11-Inch 3G"
116-
case .iPadPro11inch4G: return "iPad Pro 11-Inch 4G"
117-
case .iPadPro12d9inch1G: return "iPad Pro 12.9-Inch 1G"
118-
case .iPadPro12d9inch2G: return "iPad Pro 12.9-Inch 2G"
119-
case .iPadPro12d9inch3G: return "iPad Pro 12.9-Inch 3G"
120-
case .iPadPro12d9inch4G: return "iPad Pro 12.9-Inch 4G"
121-
case .iPadPro12d9inch5G: return "iPad Pro 12.9-Inch 5G"
122-
case .iPadPro12d9inch6G: return "iPad Pro 12.9-Inch 6G"
123-
124-
// TVs
125-
case .appleTV4G: return "Apple TV 4G"
126-
case .appleTV4K: return "Apple TV 4K"
127-
case .appleTV4K2G: return "Apple TV 4K 2G"
128-
case .appleTV4K3G: return "Apple TV 4K 3G"
129-
130-
// Watches
131-
case .appleWatch38mm: return "Apple Watch Original 38mm"
132-
case .appleWatch42mm: return "Apple Watch Original 42mm"
133-
case .appleWatch1S38mm: return "Apple Watch Series 1 38mm"
134-
case .appleWatch1S42mm: return "Apple Watch Series 1 42mm"
135-
case .appleWatch2S38mm: return "Apple Watch Series 2 38mm"
136-
case .appleWatch2S42mm: return "Apple Watch Series 2 42mm"
137-
case .appleWatch3S38mm: return "Apple Watch Series 3 38mm"
138-
case .appleWatch3S42mm: return "Apple Watch Series 3 42mm"
139-
case .appleWatch4S40mm: return "Apple Watch Series 4 40mm"
140-
case .appleWatch4S44mm: return "Apple Watch Series 4 44mm"
141-
case .appleWatch5S40mm: return "Apple Watch Series 5 40mm"
142-
case .appleWatch5S44mm: return "Apple Watch Series 5 44mm"
143-
case .appleWatch6S40mm: return "Apple Watch Series 6 40mm"
144-
case .appleWatch6S44mm: return "Apple Watch Series 6 44mm"
145-
case .appleWatch7S41mm: return "Apple Watch Series 7 41mm"
146-
case .appleWatch7S45mm: return "Apple Watch Series 7 45mm"
147-
case .appleWatch8S41mm: return "Apple Watch Series 8 41mm"
148-
case .appleWatch8S45mm: return "Apple Watch Series 8 45mm"
149-
case .appleWatch9S41mm: return "Apple Watch Series 9 41mm"
150-
case .appleWatch9S45mm: return "Apple Watch Series 9 45mm"
151-
case .appleWatchSE40mm: return "Apple Watch SE1 40mm"
152-
case .appleWatchSE44mm: return "Apple Watch SE1 44mm"
153-
case .appleWatchSE2G40mm: return "Apple Watch SE2 40mm"
154-
case .appleWatchSE2G44mm: return "Apple Watch SE2 44mm"
155-
case .appleWatchUltra: return "Apple Watch Ultra 1"
156-
case .appleWatchUltra2: return "Apple Watch Ultra 2"
157-
158-
case .iPadSimulator(let model, let arch): return "Simulator \(model.name) @ \(arch)"
159-
case .iPhoneSimulator(let model, let arch): return "Simulator \(model.name) @ \(arch)"
160-
case .appleTVSimulator(let model, let arch): return "Simulator \(model.name) @ \(arch)"
161-
case .watchSimulator(let model, let arch): return "Simulator \(model.name) @ \(arch)"
162-
163-
case .iPhoneUnknown(let model): return "Unknown iPhone: \(model)"
164-
case .iPadUnknown(let model): return "Unknown iPad: \(model)"
165-
case .iPodUnknown(let model): return "Unknown iPod: \(model)"
166-
case .appleTVUnknown(let model): return "Unknown AppleTV: \(model)"
167-
case .unknown(let model): return "Unknown device: \(model)"
168-
case .macUnknown(let model): return "Unknown Mac: \(model)"
169-
170-
case .macCatalyst: return "Mac Catalyst"
171-
case .macDesignedForIpad: return "Mac Designed for iPad"
172-
case .mac(let variant): return "Mac \(variant.name)"
173-
174-
}
175-
*/
17627
}
17728
}

Sources/DeviceIdentificator/DeviceModel.swift

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import Foundation
33
import WatchKit
44
#endif
55

6-
public indirect enum DeviceModel: Equatable, Hashable, RawRepresentable, CaseIterable, CustomStringConvertible {
6+
public indirect enum DeviceModel: Equatable, CaseIterable, CustomStringConvertible {
77
public static let current: DeviceModel = {
88
#if os(macOS)
99
let service = IOServiceGetMatchingService(kIOMasterPortDefault,
@@ -43,13 +43,4 @@ public indirect enum DeviceModel: Equatable, Hashable, RawRepresentable, CaseIte
4343
case macDesignedForIpad
4444
case unknown(model: String)
4545
case simulator(DeviceModel, arch: String)
46-
47-
public init(deviceIdentifier: String) {
48-
self = DeviceModel(rawValue: deviceIdentifier) ?? .unknown(model: deviceIdentifier)
49-
}
50-
51-
// - Hashable
52-
public func hash(into hasher: inout Hasher) {
53-
hasher.combine(rawValue)
54-
}
5546
}
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import Foundation
22

3-
public extension AppleTVModel {
3+
public extension DeviceModel.AppleTVModel {
44
var name: String {
55
switch self {
6-
case .appleTV4G: return "Apple TV 4G"
7-
case .appleTV4K: return "Apple TV 4K"
8-
case .appleTV4K2G: return "Apple TV 4K 2G"
9-
case .appleTV4K3G: return "Apple TV 4K 3G"
6+
case .tvHD: return "Apple TV 4G"
7+
case .tv4K: return "Apple TV 4K"
8+
case .tv4K2G: return "Apple TV 4K 2G"
9+
case .tv4K3G: return "Apple TV 4K 3G"
1010
}
1111
}
1212
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import Foundation
2+
3+
public extension DeviceModel.AppleTVModel {
4+
var processor: DeviceModel.Processor {
5+
switch self {
6+
case .tvHD: return .appleA8
7+
case .tv4K: return .appleA10XFusion
8+
case .tv4K2G: return .appleA12Bionic
9+
case .tv4K3G: return .appleA15Bionic
10+
}
11+
}
12+
}
Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import Foundation
22

3-
public enum AppleTVModel: String, Equatable, CaseIterable {
4-
case appleTV4G = "AppleTV5,3"
5-
case appleTV4K = "AppleTV6,2"
6-
case appleTV4K2G = "AppleTV11,1"
7-
case appleTV4K3G = "AppleTV14,1"
3+
public extension DeviceModel {
4+
enum AppleTVModel: String, Equatable, CaseIterable {
5+
case tvHD = "AppleTV5,3"
6+
case tv4K = "AppleTV6,2"
7+
case tv4K2G = "AppleTV11,1"
8+
case tv4K3G = "AppleTV14,1"
9+
}
810
}

0 commit comments

Comments
 (0)