Skip to content

Commit 66527d6

Browse files
committed
wip
1 parent d1c7cdf commit 66527d6

File tree

1 file changed

+74
-58
lines changed

1 file changed

+74
-58
lines changed

Sources/PlatformVersion.swift

Lines changed: 74 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,195 +1,211 @@
11
import Foundation
22

3+
public enum PlatformVersionCondition {
4+
case past
5+
case current
6+
case future
7+
}
8+
39
public protocol PlatformVersion {
4-
var isCurrent: Bool { get }
10+
var condition: PlatformVersionCondition { get }
11+
}
12+
13+
extension PlatformVersion {
14+
var isCurrent: Bool {
15+
condition == .current
16+
}
17+
18+
var isCurrentOrPast: Bool {
19+
condition == .current || condition == .past
20+
}
521
}
622

723
public struct iOSVersion: PlatformVersion {
8-
public let isCurrent: Bool
24+
public let condition: PlatformVersionCondition
925

10-
public init(isCurrent: () -> Bool) {
11-
self.isCurrent = isCurrent()
26+
public init(condition: () -> PlatformVersionCondition) {
27+
self.condition = condition()
1228
}
1329
}
1430

1531
extension iOSVersion {
1632
public static let v13 = iOSVersion {
1733
if #available(iOS 14, *) {
18-
return false
34+
return .past
1935
}
2036
if #available(iOS 13, *) {
21-
return true
37+
return .current
2238
}
23-
return false
39+
return .future
2440
}
2541

2642
public static let v14 = iOSVersion {
2743
if #available(iOS 15, *) {
28-
return false
44+
return .past
2945
}
3046
if #available(iOS 14, *) {
31-
return true
47+
return .current
3248
}
33-
return false
49+
return .future
3450
}
3551

3652
public static let v15 = iOSVersion {
3753
if #available(iOS 16, *) {
38-
return false
54+
return .past
3955
}
4056
if #available(iOS 15, *) {
41-
return true
57+
return .current
4258
}
43-
return false
59+
return .future
4460
}
4561

4662
public static let v16 = iOSVersion {
4763
if #available(iOS 17, *) {
48-
return false
64+
return .past
4965
}
5066
if #available(iOS 16, *) {
51-
return true
67+
return .current
5268
}
53-
return false
69+
return .future
5470
}
5571

5672
public static let v17 = iOSVersion {
5773
if #available(iOS 18, *) {
58-
return false
74+
return .past
5975
}
6076
if #available(iOS 17, *) {
61-
return true
77+
return .current
6278
}
63-
return false
79+
return .future
6480
}
6581
}
6682

6783
public struct tvOSVersion: PlatformVersion {
68-
public let isCurrent: Bool
84+
public let condition: PlatformVersionCondition
6985

70-
public init(isCurrent: () -> Bool) {
71-
self.isCurrent = isCurrent()
86+
public init(condition: () -> PlatformVersionCondition) {
87+
self.condition = condition()
7288
}
7389
}
7490

7591
extension tvOSVersion {
7692
public static let v13 = tvOSVersion {
7793
if #available(tvOS 14, *) {
78-
return false
94+
return .past
7995
}
8096
if #available(tvOS 13, *) {
81-
return true
97+
return .current
8298
}
83-
return false
99+
return .future
84100
}
85101

86102
public static let v14 = tvOSVersion {
87103
if #available(tvOS 15, *) {
88-
return false
104+
return .past
89105
}
90106
if #available(tvOS 14, *) {
91-
return true
107+
return .current
92108
}
93-
return false
109+
return .future
94110
}
95111

96112
public static let v15 = tvOSVersion {
97113
if #available(tvOS 16, *) {
98-
return false
114+
return .past
99115
}
100116
if #available(tvOS 15, *) {
101-
return true
117+
return .current
102118
}
103-
return false
119+
return .future
104120
}
105121

106122
public static let v16 = tvOSVersion {
107123
if #available(tvOS 17, *) {
108-
return false
124+
return .past
109125
}
110126
if #available(tvOS 16, *) {
111-
return true
127+
return .current
112128
}
113-
return false
129+
return .future
114130
}
115131

116132
public static let v17 = tvOSVersion {
117133
if #available(tvOS 18, *) {
118-
return false
134+
return .past
119135
}
120136
if #available(tvOS 17, *) {
121-
return true
137+
return .current
122138
}
123-
return false
139+
return .future
124140
}
125141
}
126142

127143
public struct macOSVersion: PlatformVersion {
128-
public let isCurrent: Bool
144+
public let condition: PlatformVersionCondition
129145

130-
public init(isCurrent: () -> Bool) {
131-
self.isCurrent = isCurrent()
146+
public init(condition: () -> PlatformVersionCondition) {
147+
self.condition = condition()
132148
}
133149
}
134150

135151
extension macOSVersion {
136152
public static let v10_15 = macOSVersion {
137153
if #available(macOS 11, *) {
138-
return false
154+
return .past
139155
}
140156
if #available(macOS 10.15, *) {
141-
return true
157+
return .current
142158
}
143-
return false
159+
return .future
144160
}
145161

146162
public static let v10_15_4 = macOSVersion {
147163
if #available(macOS 11, *) {
148-
return false
164+
return .past
149165
}
150166
if #available(macOS 10.15.4, *) {
151-
return true
167+
return .current
152168
}
153-
return false
169+
return .future
154170
}
155171

156172
public static let v11 = macOSVersion {
157173
if #available(macOS 12, *) {
158-
return false
174+
return .past
159175
}
160176
if #available(macOS 11, *) {
161-
return true
177+
return .current
162178
}
163-
return false
179+
return .future
164180
}
165181

166182
public static let v12 = macOSVersion {
167183
if #available(macOS 13, *) {
168-
return false
184+
return .past
169185
}
170186
if #available(macOS 12, *) {
171-
return true
187+
return .current
172188
}
173-
return false
189+
return .future
174190
}
175191

176192
public static let v13 = macOSVersion {
177193
if #available(macOS 14, *) {
178-
return false
194+
return .past
179195
}
180196
if #available(macOS 13, *) {
181-
return true
197+
return .current
182198
}
183-
return false
199+
return .future
184200
}
185201

186202
public static let v14 = macOSVersion {
187203
if #available(macOS 15, *) {
188-
return false
204+
return .past
189205
}
190206
if #available(macOS 14, *) {
191-
return true
207+
return .current
192208
}
193-
return false
209+
return .future
194210
}
195211
}

0 commit comments

Comments
 (0)