-
Notifications
You must be signed in to change notification settings - Fork 370
Expand file tree
/
Copy pathXcode.swift
More file actions
94 lines (84 loc) · 2.76 KB
/
Xcode.swift
File metadata and controls
94 lines (84 loc) · 2.76 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
import AppKit
import Foundation
import Version
import Path
import XcodesKit
public struct XcodeID: Codable, Hashable, Identifiable {
public let version: Version
public let architectures: [Architecture]?
public var id: String {
let architectures = architectures?.map { $0.rawValue}.joined() ?? ""
return version.description + architectures
}
public init(version: Version, architectures: [Architecture]? = nil) {
self.version = version
self.architectures = architectures
}
public static func == (lhs: Self, rhs: Self) -> Bool {
// First compare versions (using only semVer components) then compare architectures
lhs.version.isEquivalent(to: rhs.version) && lhs.architectures == rhs.architectures
}
}
struct Xcode: Identifiable, CustomStringConvertible {
var version: Version {
return id.version
}
/// Other Xcode versions that have the same build identifier
let identicalBuilds: [XcodeID]
var installState: XcodeInstallState
let selected: Bool
let icon: NSImage?
let requiredMacOSVersion: String?
let releaseNotesURL: URL?
let releaseDate: Date?
let sdks: SDKs?
let compilers: Compilers?
let downloadFileSize: Int64?
let architectures: [Architecture]?
let id: XcodeID
init(
version: Version,
identicalBuilds: [XcodeID] = [],
installState: XcodeInstallState,
selected: Bool,
icon: NSImage?,
requiredMacOSVersion: String? = nil,
releaseNotesURL: URL? = nil,
releaseDate: Date? = nil,
sdks: SDKs? = nil,
compilers: Compilers? = nil,
downloadFileSize: Int64? = nil,
architectures: [Architecture]? = nil
) {
self.identicalBuilds = identicalBuilds
self.installState = installState
self.selected = selected
self.icon = icon
self.requiredMacOSVersion = requiredMacOSVersion
self.releaseNotesURL = releaseNotesURL
self.releaseDate = releaseDate
self.sdks = sdks
self.compilers = compilers
self.downloadFileSize = downloadFileSize
self.architectures = architectures
self.id = XcodeID(version: version, architectures: architectures)
}
var description: String {
version.appleDescription
}
var downloadFileSizeString: String? {
if let downloadFileSize = downloadFileSize {
return ByteCountFormatter.string(fromByteCount: downloadFileSize, countStyle: .file)
} else {
return nil
}
}
var installedPath: Path? {
switch installState {
case .installed(let path):
return path
default:
return nil
}
}
}