1
1
import SwiftUI
2
2
3
- public struct PlatformViewVersions < SwiftUIViewType: IntrospectableViewType , PlatformSpecificEntity: PlatformEntity > {
4
- let isCurrent : Bool
3
+ public struct PlatformViewVersionGroup < SwiftUIViewType: IntrospectableViewType , PlatformSpecificEntity: PlatformEntity > {
4
+ let containsCurrent : Bool
5
5
let selector : IntrospectionSelector < PlatformSpecificEntity > ?
6
6
7
7
private init < Version: PlatformVersion > (
8
8
_ versions: [ PlatformViewVersion < Version , SwiftUIViewType , PlatformSpecificEntity > ]
9
9
) {
10
10
if let currentVersion = versions. first ( where: \. isCurrent) {
11
- self . isCurrent = true
11
+ self . containsCurrent = true
12
12
self . selector = currentVersion. selector
13
13
} else {
14
- self . isCurrent = false
14
+ self . containsCurrent = false
15
15
self . selector = nil
16
16
}
17
17
}
@@ -36,14 +36,41 @@ public typealias tvOSViewVersion<SwiftUIViewType: IntrospectableViewType, Platfo
36
36
public typealias macOSViewVersion < SwiftUIViewType: IntrospectableViewType , PlatformSpecificEntity: PlatformEntity > =
37
37
PlatformViewVersion < macOSVersion , SwiftUIViewType , PlatformSpecificEntity >
38
38
39
- public struct PlatformViewVersion < Version: PlatformVersion , SwiftUIViewType: IntrospectableViewType , PlatformSpecificEntity: PlatformEntity > {
40
- let isCurrent : Bool
41
- let selector : IntrospectionSelector < PlatformSpecificEntity > ?
39
+ public enum PlatformViewVersion < Version: PlatformVersion , SwiftUIViewType: IntrospectableViewType , PlatformSpecificEntity: PlatformEntity > {
40
+ case available( Version , IntrospectionSelector < PlatformSpecificEntity > ? )
41
+ case unavailable
42
+
43
+ var isCurrent : Bool {
44
+ switch self {
45
+ case . available( let version, _) :
46
+ return version. isCurrent
47
+ case . unavailable:
48
+ return false
49
+ }
50
+ }
51
+
52
+ var isCurrentOrPast : Bool {
53
+ switch self {
54
+ case . available( let version, _) :
55
+ return version. isCurrentOrPast
56
+ case . unavailable:
57
+ return false
58
+ }
59
+ }
60
+
61
+ var selector : IntrospectionSelector < PlatformSpecificEntity > ? {
62
+ switch self {
63
+ case . available( _, let selector) :
64
+ return selector
65
+ case . unavailable:
66
+ return nil
67
+ }
68
+ }
42
69
}
43
70
44
71
extension PlatformViewVersion {
45
72
@_spi ( Internals) public init ( for version: Version , selector: IntrospectionSelector < PlatformSpecificEntity > ? = nil ) {
46
- self . init ( isCurrent : version. isCurrent , selector : selector)
73
+ self = . available ( version, selector)
47
74
}
48
75
49
76
@_spi ( Internals) public static func unavailable( file: StaticString = #file, line: UInt = #line) -> Self {
@@ -60,6 +87,6 @@ extension PlatformViewVersion {
60
87
https://github.com/siteline/swiftui-introspect/issues/new?title=` \( fileName) : \( line) `+should+be+marked+unavailable
61
88
"""
62
89
)
63
- return Self ( isCurrent : false , selector : nil )
90
+ return . unavailable
64
91
}
65
92
}
0 commit comments