@@ -7,6 +7,35 @@ import Glibc
7
7
// FIXME: The `Error == Never` constraint is retained for Swift 4.0.x
8
8
// compatibility, since `BindingSource` did not impose such constraint
9
9
// due to the absence of conditional conformance.
10
+ #if swift(>=5.7)
11
+
12
+ /// Represents a property that allows observation of its changes.
13
+ ///
14
+ /// Only classes can conform to this protocol, because having a signal
15
+ /// for changes over time implies the origin must have a unique identity.
16
+ public protocol PropertyProtocol < Value> : AnyObject , BindingSource {
17
+ /// The current value of the property.
18
+ var value : Value { get }
19
+
20
+ /// The values producer of the property.
21
+ ///
22
+ /// It produces a signal that sends the property's current value,
23
+ /// followed by all changes over time. It completes when the property
24
+ /// has deinitialized, or has no further change.
25
+ ///
26
+ /// - note: If `self` is a composed property, the producer would be
27
+ /// bound to the lifetime of its sources.
28
+ var producer : SignalProducer < Value , Never > { get }
29
+
30
+ /// A signal that will send the property's changes over time. It
31
+ /// completes when the property has deinitialized, or has no further
32
+ /// change.
33
+ ///
34
+ /// - note: If `self` is a composed property, the signal would be
35
+ /// bound to the lifetime of its sources.
36
+ var signal : Signal < Value , Never > { get }
37
+ }
38
+ #else
10
39
11
40
/// Represents a property that allows observation of its changes.
12
41
///
@@ -34,7 +63,20 @@ public protocol PropertyProtocol: AnyObject, BindingSource {
34
63
/// bound to the lifetime of its sources.
35
64
var signal : Signal < Value , Never > { get }
36
65
}
66
+ #endif
37
67
68
+ #if swift(>=5.7)
69
+ /// Represents an observable property that can be mutated directly.
70
+ public protocol MutablePropertyProtocol < Value> : PropertyProtocol , BindingTargetProvider {
71
+ associatedtype Value
72
+
73
+ /// The current value of the property.
74
+ var value : Value { get set }
75
+
76
+ /// The lifetime of the property.
77
+ var lifetime : Lifetime { get }
78
+ }
79
+ #else
38
80
/// Represents an observable property that can be mutated directly.
39
81
public protocol MutablePropertyProtocol : PropertyProtocol , BindingTargetProvider {
40
82
/// The current value of the property.
@@ -43,6 +85,7 @@ public protocol MutablePropertyProtocol: PropertyProtocol, BindingTargetProvider
43
85
/// The lifetime of the property.
44
86
var lifetime : Lifetime { get }
45
87
}
88
+ #endif
46
89
47
90
/// Default implementation of `BindingTargetProvider` for mutable properties.
48
91
extension MutablePropertyProtocol {
@@ -51,6 +94,29 @@ extension MutablePropertyProtocol {
51
94
}
52
95
}
53
96
97
+ #if swift(>=5.7)
98
+ /// Represents a mutable property that can be safety composed by exposing its
99
+ /// synchronization mechanic through the defined closure-based interface.
100
+ public protocol ComposableMutablePropertyProtocol < Value> : MutablePropertyProtocol {
101
+ /// Atomically performs an arbitrary action using the current value of the
102
+ /// variable.
103
+ ///
104
+ /// - parameters:
105
+ /// - action: A closure that accepts current property value.
106
+ ///
107
+ /// - returns: the result of the action.
108
+ func withValue< Result> ( _ action: ( Value ) throws -> Result ) rethrows -> Result
109
+
110
+ /// Atomically modifies the variable.
111
+ ///
112
+ /// - parameters:
113
+ /// - action: A closure that accepts old property value and returns a new
114
+ /// property value.
115
+ ///
116
+ /// - returns: The result of the action.
117
+ func modify< Result> ( _ action: ( inout Value ) throws -> Result ) rethrows -> Result
118
+ }
119
+ #else
54
120
/// Represents a mutable property that can be safety composed by exposing its
55
121
/// synchronization mechanic through the defined closure-based interface.
56
122
public protocol ComposableMutablePropertyProtocol : MutablePropertyProtocol {
@@ -72,6 +138,7 @@ public protocol ComposableMutablePropertyProtocol: MutablePropertyProtocol {
72
138
/// - returns: The result of the action.
73
139
func modify< Result> ( _ action: ( inout Value ) throws -> Result ) rethrows -> Result
74
140
}
141
+ #endif
75
142
76
143
// Property operators.
77
144
//
0 commit comments