9
9
/**
10
10
Describes any Type (Class or Thread) to which Observers can Subscribe.
11
11
- Author: Simon J. Stuart
12
- - Version: 1.1 .0
12
+ - Version: 2.0 .0
13
13
- Important: This Protocol can only be applied to Class and Thread types.
14
14
15
15
See the Base Implementations `ObservableClass` and `ObservableThread`
16
16
*/
17
17
@available ( macOS 10 . 15 , iOS 13 . 0 , tvOS 13 . 0 , watchOS 6 . 0 , * )
18
18
public protocol KeyedObservable : Observable {
19
- /**
20
- Keyed Observables must declare a `TKey` type which must conform to `Hashable`
21
- - Author: Simon J. Stuart
22
- - Version: 1.1.0
23
- */
24
- associatedtype TKey : Hashable
25
-
26
19
/**
27
20
Registers an Observer against this Observable Type for the given Key
28
21
- Author: Simon J. Stuart
29
- - Version: 1.1 .0
22
+ - Version: 2.0 .0
30
23
- Parameters:
31
24
- key: The Key for which this Observer is subscribed
32
25
- observer: A reference to a Class (or Thread) conforming to the desired Observer Protocol, inferred from Generics as `TObservationProtocol`
33
26
34
27
Call this every time you need to register an Observer with your Observable.
35
28
*/
36
- func addKeyedObserver< TObservationProtocol: AnyObject > ( for key: TKey , _ observer: TObservationProtocol )
29
+ func addKeyedObserver< TObservationProtocol: AnyObject , TKey : Hashable > ( key: TKey , _ observer: TObservationProtocol )
37
30
38
31
/**
39
32
Registers the Observers against this Observable Type for the given Key
40
33
- Author: Simon J. Stuart
41
- - Version: 1.1 .0
34
+ - Version: 2.0 .0
42
35
- Parameters:
43
36
- key: The Key for which this Observer is subscribed
44
37
- observers: A reference to a Classes (or Threads) conforming to the desired Observer Protocol, inferred from Generics as `TObservationProtocol`
45
38
46
39
Call this every time you need to register an Observer with your Observable.
47
40
*/
48
- func addKeyedObserver< TObservationProtocol: AnyObject > ( for key: TKey , _ observers: [ TObservationProtocol ] )
41
+ func addKeyedObserver< TObservationProtocol: AnyObject , TKey : Hashable > ( key: TKey , _ observers: [ TObservationProtocol ] )
49
42
50
43
/**
51
44
Registers an Observer against this Observable Type for the given Keys
52
45
- Author: Simon J. Stuart
53
- - Version: 1.1 .0
46
+ - Version: 2.0 .0
54
47
- Parameters:
55
48
- keys: The Keys for which this Observer is subscribed
56
49
- observer: A reference to a Class (or Thread) conforming to the desired Observer Protocol, inferred from Generics as `TObservationProtocol`
57
50
58
51
Call this every time you need to register an Observer with your Observable.
59
52
*/
60
- func addKeyedObserver< TObservationProtocol: AnyObject > ( for keys: [ TKey ] , _ observer: TObservationProtocol )
53
+ func addKeyedObserver< TObservationProtocol: AnyObject , TKey : Hashable > ( keys: [ TKey ] , _ observer: TObservationProtocol )
61
54
62
55
/**
63
56
Registers the given Observers against this Observable Type for the given Keys
64
57
- Author: Simon J. Stuart
65
- - Version: 1.1 .0
58
+ - Version: 2.0 .0
66
59
- Parameters:
67
60
- keys: The Keys for which this Observer is subscribed
68
61
- observers: A reference to a Classes (or Threads) conforming to the desired Observer Protocol, inferred from Generics as `TObservationProtocol`
69
62
70
63
Call this every time you need to register an Observer with your Observable.
71
64
*/
72
- func addKeyedObserver< TObservationProtocol: AnyObject > ( for keys: [ TKey ] , _ observers: [ TObservationProtocol ] )
65
+ func addKeyedObserver< TObservationProtocol: AnyObject , TKey : Hashable > ( keys: [ TKey ] , _ observers: [ TObservationProtocol ] )
73
66
74
67
/**
75
68
Removes an Observer from this Observable Type for the given Key
76
69
- Author: Simon J. Stuart
77
- - Version: 1.1 .0
70
+ - Version: 2.0 .0
78
71
- Parameters:
79
72
- key: The Key for which this Observer was subscribed
80
73
- observer: A reference to a Class (or Thread) conforming to the desired Observer Protocol, inferred from Generics as `TObservationProtocol`
81
74
82
75
Call this if you need to explicitly unregister an Observer from your Observable.
83
76
*/
84
- func removeKeyedObserver< TObservationProtocol: AnyObject > ( for key: TKey , _ observer: TObservationProtocol )
77
+ func removeKeyedObserver< TObservationProtocol: AnyObject , TKey : Hashable > ( key: TKey , _ observer: TObservationProtocol )
85
78
86
79
/**
87
80
Removes all given Observers from this Observable Type for the given Key
88
81
- Author: Simon J. Stuart
89
- - Version: 1.1 .0
82
+ - Version: 2.0 .0
90
83
- Parameters:
91
84
- key: The Key for which this Observer was subscribed
92
85
- observers: A reference to a Classes (or Threads) conforming to the desired Observer Protocol, inferred from Generics as `TObservationProtocol`
93
86
94
87
Call this if you need to explicitly unregister an Observer from your Observable.
95
88
*/
96
- func removeKeyedObserver< TObservationProtocol: AnyObject > ( for key: TKey , _ observers: [ TObservationProtocol ] )
89
+ func removeKeyedObserver< TObservationProtocol: AnyObject , TKey : Hashable > ( key: TKey , _ observers: [ TObservationProtocol ] )
97
90
98
91
/**
99
92
Removes an Observer from this Observable Type for the given Keys
100
93
- Author: Simon J. Stuart
101
- - Version: 1.1 .0
94
+ - Version: 2.0 .0
102
95
- Parameters:
103
96
- keys: The Keys for which this Observer was subscribed
104
97
- observer: A reference to a Class (or Thread) conforming to the desired Observer Protocol, inferred from Generics as `TObservationProtocol`
105
98
106
99
Call this if you need to explicitly unregister an Observer from your Observable.
107
100
*/
108
- func removeKeyedObserver< TObservationProtocol: AnyObject > ( for keys: [ TKey ] , _ observer: TObservationProtocol )
101
+ func removeKeyedObserver< TObservationProtocol: AnyObject , TKey : Hashable > ( keys: [ TKey ] , _ observer: TObservationProtocol )
109
102
110
103
/**
111
104
Removes an Observer from this Observable Type for the given Keys
112
105
- Author: Simon J. Stuart
113
- - Version: 1.1 .0
106
+ - Version: 2.0 .0
114
107
- Parameters:
115
108
- keys: The Keys for which this Observer was subscribed
116
109
- observers: A reference to a Classes (or Threads) conforming to the desired Observer Protocol, inferred from Generics as `TObservationProtocol`
117
110
118
111
Call this if you need to explicitly unregister an Observer from your Observable.
119
112
*/
120
- func removeKeyedObserver< TObservationProtocol: AnyObject > ( for keys: [ TKey ] , _ observers: [ TObservationProtocol ] )
113
+ func removeKeyedObserver< TObservationProtocol: AnyObject , TKey : Hashable > ( keys: [ TKey ] , _ observers: [ TObservationProtocol ] )
121
114
122
115
/**
123
116
Iterates all of the registered Observers for this Observable and invokes against them your defined Closure Method for the given Key.
124
117
- Author: Simon J. Stuart
125
- - Version: 1.1 .0
118
+ - Version: 2.0 .0
126
119
- Parameters:
127
120
- key: The Key to which the Observation relates.
128
121
- code: The Closure you wish to invoke for each Observer
@@ -140,12 +133,12 @@ public protocol KeyedObservable: Observable {
140
133
}
141
134
````
142
135
*/
143
- func withKeyedObservers< TObservationProtocol> ( for key: TKey , _ code: @escaping ( _ key: TKey , _ observer: TObservationProtocol ) -> ( ) )
136
+ func withKeyedObservers< TObservationProtocol, TKey : Hashable > ( key: TKey , _ code: @escaping ( _ key: TKey , _ observer: TObservationProtocol ) -> ( ) )
144
137
145
138
/**
146
139
Iterates all of the registered Observers for this Observable and invokes against them your defined Closure Method for the given Keys.
147
140
- Author: Simon J. Stuart
148
- - Version: 1.1 .0
141
+ - Version: 2.0 .0
149
142
- Parameters:
150
143
- keys: The Keys to which the Observation relates.
151
144
- code: The Closure you wish to invoke for each Observer
@@ -163,93 +156,93 @@ public protocol KeyedObservable: Observable {
163
156
}
164
157
````
165
158
*/
166
- func withKeyedObservers< TObservationProtocol> ( for keys: [ TKey ] , _ code: @escaping ( _ key: TKey , _ observer: TObservationProtocol ) -> ( ) )
159
+ func withKeyedObservers< TObservationProtocol, TKey : Hashable > ( keys: [ TKey ] , _ code: @escaping ( _ key: TKey , _ observer: TObservationProtocol ) -> ( ) )
167
160
}
168
161
169
162
/**
170
163
This extension just implements the simple Macros universally for any implementation of the `KeyedObserverable` protocol
171
164
- Author: Simon J. Stuart
172
- - Version: 1.1 .0
165
+ - Version: 2.0 .0
173
166
*/
174
167
extension KeyedObservable {
175
168
/**
176
169
Simply iterates multiple observers, and for each, invokes the `addKeyedObserver` implementation taking just that one observer.
177
170
- Author: Simon J. Stuart
178
- - Version: 1.1 .0
171
+ - Version: 2.0 .0
179
172
*/
180
- public func addKeyedObserver< TObservationProtocol: AnyObject > ( for key: TKey , _ observers: [ TObservationProtocol ] ) {
173
+ public func addKeyedObserver< TObservationProtocol: AnyObject , TKey : Hashable > ( key: TKey , _ observers: [ TObservationProtocol ] ) {
181
174
for observer in observers {
182
- addKeyedObserver ( for : key, observer)
175
+ addKeyedObserver ( key : key, observer)
183
176
}
184
177
}
185
178
186
179
/**
187
180
Simply iterates multiple keys, and for each, invokes the `addKeyedObserver` implementation taking just that one key.
188
181
- Author: Simon J. Stuart
189
- - Version: 1.1 .0
182
+ - Version: 2.0 .0
190
183
*/
191
- public func addKeyedObserver< TObservationProtocol: AnyObject > ( for keys: [ TKey ] , _ observer: TObservationProtocol ) {
184
+ public func addKeyedObserver< TObservationProtocol: AnyObject , TKey : Hashable > ( keys: [ TKey ] , _ observer: TObservationProtocol ) {
192
185
for key in keys {
193
- addKeyedObserver ( for : key, observer)
186
+ addKeyedObserver ( key : key, observer)
194
187
}
195
188
}
196
189
197
190
/**
198
191
Simply iterates multiple keys and observers, and for each, invokes the `addKeyedObserver` implementation taking just that one key and observer.
199
192
- Author: Simon J. Stuart
200
- - Version: 1.1 .0
193
+ - Version: 2.0 .0
201
194
*/
202
- public func addKeyedObserver< TObservationProtocol: AnyObject > ( for keys: [ TKey ] , _ observers: [ TObservationProtocol ] ) {
195
+ public func addKeyedObserver< TObservationProtocol: AnyObject , TKey : Hashable > ( keys: [ TKey ] , _ observers: [ TObservationProtocol ] ) {
203
196
for key in keys {
204
197
for observer in observers {
205
- addKeyedObserver ( for : key, observer)
198
+ addKeyedObserver ( key : key, observer)
206
199
}
207
200
}
208
201
}
209
202
210
203
/**
211
204
Simply iterates multiple observers, and for each, invokes the `removeKeyedObserver` implementation taking just that one observer.
212
205
- Author: Simon J. Stuart
213
- - Version: 1.1 .0
206
+ - Version: 2.0 .0
214
207
*/
215
- public func removeKeyedObserver< TObservationProtocol: AnyObject > ( for key: TKey , _ observers: [ TObservationProtocol ] ) {
208
+ public func removeKeyedObserver< TObservationProtocol: AnyObject , TKey : Hashable > ( key: TKey , _ observers: [ TObservationProtocol ] ) {
216
209
for observer in observers {
217
- removeKeyedObserver ( for : key, observer)
210
+ removeKeyedObserver ( key : key, observer)
218
211
}
219
212
}
220
213
221
214
/**
222
215
Simply iterates multiple keys, and for each, invokes the `removeKeyedObserver` implementation taking just that one key.
223
216
- Author: Simon J. Stuart
224
- - Version: 1.1 .0
217
+ - Version: 2.0 .0
225
218
*/
226
- public func removeKeyedObserver< TObservationProtocol: AnyObject > ( for keys: [ TKey ] , _ observer: TObservationProtocol ) {
219
+ public func removeKeyedObserver< TObservationProtocol: AnyObject , TKey : Hashable > ( keys: [ TKey ] , _ observer: TObservationProtocol ) {
227
220
for key in keys {
228
- removeKeyedObserver ( for : key, observer)
221
+ removeKeyedObserver ( key : key, observer)
229
222
}
230
223
}
231
224
232
225
/**
233
226
Simply iterates multiple keys, and for each, invokes the `removeKeyedObserver` implementation taking just that one key and the one observer.
234
227
- Author: Simon J. Stuart
235
- - Version: 1.1 .0
228
+ - Version: 2.0 .0
236
229
*/
237
- public func removeKeyedObserver< TObservationProtocol: AnyObject > ( for keys: [ TKey ] , _ observers: [ TObservationProtocol ] ) {
230
+ public func removeKeyedObserver< TObservationProtocol: AnyObject , TKey : Hashable > ( keys: [ TKey ] , _ observers: [ TObservationProtocol ] ) {
238
231
for key in keys {
239
232
for observer in observers {
240
- removeKeyedObserver ( for : key, observer)
233
+ removeKeyedObserver ( key : key, observer)
241
234
}
242
235
}
243
236
}
244
237
245
238
/**
246
239
Simply iterates multiple keys, and for each, invokes the `withKeyedObservers` implementation taking just that one key.
247
240
- Author: Simon J. Stuart
248
- - Version: 1.1 .0
241
+ - Version: 2.0 .0
249
242
*/
250
- public func withKeyedObservers< TObservationProtocol> ( for keys: [ TKey ] , _ code: @escaping ( _ key: TKey , _ observer: TObservationProtocol ) -> ( ) ) {
243
+ public func withKeyedObservers< TObservationProtocol, TKey : Hashable > ( keys: [ TKey ] , _ code: @escaping ( _ key: TKey , _ observer: TObservationProtocol ) -> ( ) ) {
251
244
for key in keys {
252
- withKeyedObservers ( for : key, code)
245
+ withKeyedObservers ( key : key, code)
253
246
}
254
247
}
255
248
}
0 commit comments