@@ -7,6 +7,35 @@ import Glibc
77// FIXME: The `Error == Never` constraint is retained for Swift 4.0.x
88// compatibility, since `BindingSource` did not impose such constraint
99// 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
1039
1140/// Represents a property that allows observation of its changes.
1241///
@@ -34,7 +63,20 @@ public protocol PropertyProtocol: AnyObject, BindingSource {
3463 /// bound to the lifetime of its sources.
3564 var signal : Signal < Value , Never > { get }
3665}
66+ #endif
3767
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
3880/// Represents an observable property that can be mutated directly.
3981public protocol MutablePropertyProtocol : PropertyProtocol , BindingTargetProvider {
4082 /// The current value of the property.
@@ -43,6 +85,7 @@ public protocol MutablePropertyProtocol: PropertyProtocol, BindingTargetProvider
4385 /// The lifetime of the property.
4486 var lifetime : Lifetime { get }
4587}
88+ #endif
4689
4790/// Default implementation of `BindingTargetProvider` for mutable properties.
4891extension MutablePropertyProtocol {
@@ -51,6 +94,29 @@ extension MutablePropertyProtocol {
5194 }
5295}
5396
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
54120/// Represents a mutable property that can be safety composed by exposing its
55121/// synchronization mechanic through the defined closure-based interface.
56122public protocol ComposableMutablePropertyProtocol : MutablePropertyProtocol {
@@ -72,6 +138,7 @@ public protocol ComposableMutablePropertyProtocol: MutablePropertyProtocol {
72138 /// - returns: The result of the action.
73139 func modify< Result> ( _ action: ( inout Value ) throws -> Result ) rethrows -> Result
74140}
141+ #endif
75142
76143// Property operators.
77144//
0 commit comments