-
Notifications
You must be signed in to change notification settings - Fork 181
Expand file tree
/
Copy pathModels+Runtimes.swift
More file actions
157 lines (137 loc) · 4.59 KB
/
Copy pathModels+Runtimes.swift
File metadata and controls
157 lines (137 loc) · 4.59 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import Foundation
struct DownloadableRuntimesResponse: Decodable {
let sdkToSimulatorMappings: [SDKToSimulatorMapping]
let sdkToSeedMappings: [SDKToSeedMapping]
let refreshInterval: Int
let downloadables: [DownloadableRuntime]
let version: String
}
public struct DownloadableRuntime: Decodable {
let category: Category
let simulatorVersion: SimulatorVersion
let source: String?
let architectures: [String]?
let dictionaryVersion: Int
let contentType: ContentType
let platform: Platform
let identifier: String
let version: String
let fileSize: Int
let hostRequirements: HostRequirements?
let name: String
let authentication: Authentication?
var betaNumber: Int? {
enum Regex { static let shared = try! NSRegularExpression(pattern: "b[0-9]+") }
guard var foundString = Regex.shared.firstString(in: identifier) else { return nil }
foundString.removeFirst()
return Int(foundString)!
}
var completeVersion: String {
makeVersion(for: simulatorVersion.version, betaNumber: betaNumber)
}
var visibleIdentifier: String {
return platform.shortName + " " + completeVersion + (architectures != nil ? " \(architectures?.joined(separator: "|") ?? "")" : "")
}
}
func makeVersion(for osVersion: String, betaNumber: Int?) -> String {
let betaSuffix = betaNumber.flatMap { "-beta\($0)" } ?? ""
return osVersion + betaSuffix
}
struct SDKToSeedMapping: Decodable {
let buildUpdate: String
let platform: DownloadableRuntime.Platform
let seedNumber: Int
}
struct SDKToSimulatorMapping: Decodable {
let sdkBuildUpdate: String
let simulatorBuildUpdate: String
let sdkIdentifier: String
let downloadableIdentifiers: [String]?
}
extension DownloadableRuntime {
struct SimulatorVersion: Decodable {
let buildUpdate: String
let version: String
}
struct HostRequirements: Decodable {
let maxHostVersion: String?
let excludedHostArchitectures: [String]?
let minHostVersion: String?
let minXcodeVersion: String?
}
enum Authentication: String, Decodable {
case virtual = "virtual"
}
enum Category: String, Decodable {
case simulator = "simulator"
}
enum ContentType: String, Decodable {
case diskImage = "diskImage"
case package = "package"
case cryptexDiskImage = "cryptexDiskImage"
case patchableCryptexDiskImage = "patchableCryptexDiskImage"
}
enum Platform: String, Decodable {
case iOS = "com.apple.platform.iphoneos"
case macOS = "com.apple.platform.macosx"
case watchOS = "com.apple.platform.watchos"
case tvOS = "com.apple.platform.appletvos"
case visionOS = "com.apple.platform.xros"
var order: Int {
switch self {
case .iOS: return 1
case .macOS: return 2
case .watchOS: return 3
case .tvOS: return 4
case .visionOS: return 5
}
}
var shortName: String {
switch self {
case .iOS: return "iOS"
case .macOS: return "macOS"
case .watchOS: return "watchOS"
case .tvOS: return "tvOS"
case .visionOS: return "visionOS"
}
}
}
}
public struct InstalledRuntime: Decodable {
let build: String
let deletable: Bool
let identifier: UUID
let kind: Kind
let lastUsedAt: Date?
let path: String
let platformIdentifier: Platform
let runtimeBundlePath: String
let runtimeIdentifier: String
let signatureState: String
let state: String
let version: String
let sizeBytes: Int?
}
extension InstalledRuntime {
enum Kind: String, Decodable {
case bundled = "Bundled with Xcode"
case cryptexDiskImage = "Cryptex Disk Image"
case diskImage = "Disk Image"
case legacyDownload = "Legacy Download"
case patchableCryptexDiskImage = "Patchable Cryptex Disk Image"
}
enum Platform: String, Decodable {
case tvOS = "com.apple.platform.appletvsimulator"
case iOS = "com.apple.platform.iphonesimulator"
case watchOS = "com.apple.platform.watchsimulator"
case visionOS = "com.apple.platform.xrsimulator"
var asPlatformOS: DownloadableRuntime.Platform {
switch self {
case .watchOS: return .watchOS
case .iOS: return .iOS
case .tvOS: return .tvOS
case .visionOS: return .visionOS
}
}
}
}