@@ -25,7 +25,8 @@ extension ProgressManager {
25
25
/// - Parameter key: A key path to the custom integer property type.
26
26
public subscript< P: Property > ( dynamicMember key: KeyPath < ProgressManager . Properties , P . Type > ) -> Int where P. Value == Int , P. Summary == Int {
27
27
get {
28
- state. withLock { state in
28
+ accessObservation ( keyPath: ProgressManager . additionalPropertiesKeyPath. withLock { $0 } )
29
+ return state. withLock { state in
29
30
if P . self == ProgressManager . Properties. TotalFileCount. self {
30
31
return state. totalFileCount
31
32
} else if P . self == ProgressManager . Properties. CompletedFileCount. self {
@@ -37,35 +38,37 @@ extension ProgressManager {
37
38
}
38
39
39
40
set {
40
- let parents : [ ParentState ] ? = state. withLock { state in
41
- if P . self == ProgressManager . Properties. TotalFileCount. self {
42
- guard newValue != state. totalFileCount else {
43
- return nil
44
- }
45
- state. totalFileCount = newValue
46
- return state. parents
47
-
48
- } else if P . self == ProgressManager . Properties. CompletedFileCount. self {
49
- guard newValue != state. completedFileCount else {
50
- return nil
51
- }
52
- state. completedFileCount = newValue
53
- return state. parents
54
- } else {
55
- guard newValue != state. propertiesInt [ MetatypeWrapper ( P . self) ] else {
56
- return nil
41
+ mutateObservation ( of: ProgressManager . additionalPropertiesKeyPath. withLock { $0 } ) {
42
+ let parents : [ ParentState ] ? = state. withLock { state in
43
+ if P . self == ProgressManager . Properties. TotalFileCount. self {
44
+ guard newValue != state. totalFileCount else {
45
+ return nil
46
+ }
47
+ state. totalFileCount = newValue
48
+ return state. parents
49
+
50
+ } else if P . self == ProgressManager . Properties. CompletedFileCount. self {
51
+ guard newValue != state. completedFileCount else {
52
+ return nil
53
+ }
54
+ state. completedFileCount = newValue
55
+ return state. parents
56
+ } else {
57
+ guard newValue != state. propertiesInt [ MetatypeWrapper ( P . self) ] else {
58
+ return nil
59
+ }
60
+ state. propertiesInt [ MetatypeWrapper ( P . self) ] = newValue
61
+ return state. parents
57
62
}
58
- state. propertiesInt [ MetatypeWrapper ( P . self) ] = newValue
59
- return state. parents
60
63
}
61
- }
62
- if let parents = parents {
63
- if P . self == ProgressManager . Properties. TotalFileCount. self {
64
- markSelfDirty ( property : ProgressManager . Properties. TotalFileCount . self, parents : parents )
65
- } else if P . self == ProgressManager . Properties. CompletedFileCount. self {
66
- markSelfDirty ( property : ProgressManager . Properties . CompletedFileCount . self , parents : parents )
67
- } else {
68
- markSelfDirty ( property : MetatypeWrapper ( P . self ) , parents : parents )
64
+ if let parents = parents {
65
+ if P . self == ProgressManager . Properties . TotalFileCount . self {
66
+ markSelfDirty ( property : ProgressManager . Properties. TotalFileCount. self, parents : parents )
67
+ } else if P . self == ProgressManager . Properties. CompletedFileCount . self {
68
+ markSelfDirty ( property : ProgressManager . Properties. CompletedFileCount. self, parents : parents )
69
+ } else {
70
+ markSelfDirty ( property : MetatypeWrapper ( P . self ) , parents : parents )
71
+ }
69
72
}
70
73
}
71
74
}
@@ -80,7 +83,8 @@ extension ProgressManager {
80
83
/// - Parameter key: A key path to the custom unsigned integer property type.
81
84
public subscript< P: Property > ( dynamicMember key: KeyPath < ProgressManager . Properties , P . Type > ) -> UInt64 where P. Value == UInt64 , P. Summary == UInt64 {
82
85
get {
83
- state. withLock { state in
86
+ accessObservation ( keyPath: ProgressManager . additionalPropertiesKeyPath. withLock { $0 } )
87
+ return state. withLock { state in
84
88
if P . self == ProgressManager . Properties. TotalByteCount. self {
85
89
return state. totalByteCount
86
90
} else if P . self == ProgressManager . Properties. CompletedByteCount. self {
@@ -92,34 +96,36 @@ extension ProgressManager {
92
96
}
93
97
94
98
set {
95
- let parents : [ ParentState ] ? = state. withLock { state in
96
- if P . self == ProgressManager . Properties. TotalByteCount. self {
97
- guard newValue != state. totalByteCount else {
98
- return nil
99
+ mutateObservation ( of: ProgressManager . additionalPropertiesKeyPath. withLock { $0 } ) {
100
+ let parents : [ ParentState ] ? = state. withLock { state in
101
+ if P . self == ProgressManager . Properties. TotalByteCount. self {
102
+ guard newValue != state. totalByteCount else {
103
+ return nil
104
+ }
105
+ state. totalByteCount = newValue
106
+ return state. parents
107
+ } else if P . self == ProgressManager . Properties. CompletedByteCount. self {
108
+ guard newValue != state. completedByteCount else {
109
+ return nil
110
+ }
111
+ state. completedByteCount = newValue
112
+ return state. parents
113
+ } else {
114
+ guard newValue != state. propertiesUInt64 [ MetatypeWrapper ( P . self) ] else {
115
+ return nil
116
+ }
117
+ state. propertiesUInt64 [ MetatypeWrapper ( P . self) ] = newValue
118
+ return state. parents
99
119
}
100
- state. totalByteCount = newValue
101
- return state. parents
102
- } else if P . self == ProgressManager . Properties. CompletedByteCount. self {
103
- guard newValue != state. completedByteCount else {
104
- return nil
105
- }
106
- state. completedByteCount = newValue
107
- return state. parents
108
- } else {
109
- guard newValue != state. propertiesUInt64 [ MetatypeWrapper ( P . self) ] else {
110
- return nil
111
- }
112
- state. propertiesUInt64 [ MetatypeWrapper ( P . self) ] = newValue
113
- return state. parents
114
120
}
115
- }
116
- if let parents = parents {
117
- if P . self == ProgressManager . Properties. TotalByteCount. self {
118
- markSelfDirty ( property : ProgressManager . Properties. TotalByteCount . self, parents : parents )
119
- } else if P . self == ProgressManager . Properties. CompletedByteCount. self {
120
- markSelfDirty ( property : ProgressManager . Properties . CompletedByteCount . self , parents : parents )
121
- } else {
122
- markSelfDirty ( property : MetatypeWrapper ( P . self ) , parents : parents )
121
+ if let parents = parents {
122
+ if P . self == ProgressManager . Properties . TotalByteCount . self {
123
+ markSelfDirty ( property : ProgressManager . Properties. TotalByteCount. self, parents : parents )
124
+ } else if P . self == ProgressManager . Properties. CompletedByteCount . self {
125
+ markSelfDirty ( property : ProgressManager . Properties. CompletedByteCount. self, parents : parents )
126
+ } else {
127
+ markSelfDirty ( property : MetatypeWrapper ( P . self ) , parents : parents )
128
+ }
123
129
}
124
130
}
125
131
}
@@ -134,21 +140,24 @@ extension ProgressManager {
134
140
/// - Parameter key: A key path to the custom double property type.
135
141
public subscript< P: Property > ( dynamicMember key: KeyPath < ProgressManager . Properties , P . Type > ) -> P . Value where P. Value == Double , P. Summary == Double {
136
142
get {
137
- state. withLock { state in
143
+ accessObservation ( keyPath: ProgressManager . additionalPropertiesKeyPath. withLock { $0 } )
144
+ return state. withLock { state in
138
145
return state. propertiesDouble [ MetatypeWrapper ( P . self) ] ?? P . defaultValue
139
146
}
140
147
}
141
148
142
149
set {
143
- let parents : [ ParentState ] ? = state. withLock { state in
144
- guard newValue != state. propertiesDouble [ MetatypeWrapper ( P . self) ] else {
145
- return nil
150
+ mutateObservation ( of: ProgressManager . additionalPropertiesKeyPath. withLock { $0 } ) {
151
+ let parents : [ ParentState ] ? = state. withLock { state in
152
+ guard newValue != state. propertiesDouble [ MetatypeWrapper ( P . self) ] else {
153
+ return nil
154
+ }
155
+ state. propertiesDouble [ MetatypeWrapper ( P . self) ] = newValue
156
+ return state. parents
157
+ }
158
+ if let parents = parents {
159
+ markSelfDirty ( property: MetatypeWrapper ( P . self) , parents: parents)
146
160
}
147
- state. propertiesDouble [ MetatypeWrapper ( P . self) ] = newValue
148
- return state. parents
149
- }
150
- if let parents = parents {
151
- markSelfDirty ( property: MetatypeWrapper ( P . self) , parents: parents)
152
161
}
153
162
}
154
163
}
@@ -162,21 +171,24 @@ extension ProgressManager {
162
171
/// - Parameter key: A key path to the custom string property type.
163
172
public subscript< P: Property > ( dynamicMember key: KeyPath < ProgressManager . Properties , P . Type > ) -> String ? where P. Value == String ? , P. Summary == [ String ? ] {
164
173
get {
165
- state. withLock { state in
166
- return state. propertiesString [ MetatypeWrapper ( P . self) ] ?? P . self. defaultValue
174
+ accessObservation ( keyPath: ProgressManager . additionalPropertiesKeyPath. withLock { $0 } )
175
+ return state. withLock { state in
176
+ return state. propertiesString [ MetatypeWrapper ( P . self) ] ?? P . defaultValue
167
177
}
168
178
}
169
179
170
180
set {
171
- let parents : [ ParentState ] ? = state. withLock { state in
172
- guard newValue != state. propertiesString [ MetatypeWrapper ( P . self) ] else {
173
- return nil
181
+ mutateObservation ( of: ProgressManager . additionalPropertiesKeyPath. withLock { $0 } ) {
182
+ let parents : [ ParentState ] ? = state. withLock { state in
183
+ guard newValue != state. propertiesString [ MetatypeWrapper ( P . self) ] else {
184
+ return nil
185
+ }
186
+ state. propertiesString [ MetatypeWrapper ( P . self) ] = newValue
187
+ return state. parents
188
+ }
189
+ if let parents = parents {
190
+ markSelfDirty ( property: MetatypeWrapper ( P . self) , parents: parents)
174
191
}
175
- state. propertiesString [ MetatypeWrapper ( P . self) ] = newValue
176
- return state. parents
177
- }
178
- if let parents = parents {
179
- markSelfDirty ( property: MetatypeWrapper ( P . self) , parents: parents)
180
192
}
181
193
}
182
194
}
@@ -190,21 +202,24 @@ extension ProgressManager {
190
202
/// - Parameter key: A key path to the custom URL property type.
191
203
public subscript< P: Property > ( dynamicMember key: KeyPath < ProgressManager . Properties , P . Type > ) -> URL ? where P. Value == URL ? , P. Summary == [ URL ? ] {
192
204
get {
193
- state. withLock { state in
194
- return state. propertiesURL [ MetatypeWrapper ( P . self) ] ?? P . self. defaultValue
205
+ accessObservation ( keyPath: ProgressManager . additionalPropertiesKeyPath. withLock { $0 } )
206
+ return state. withLock { state in
207
+ return state. propertiesURL [ MetatypeWrapper ( P . self) ] ?? P . defaultValue
195
208
}
196
209
}
197
210
198
211
set {
199
- let parents : [ ParentState ] ? = state. withLock { state in
200
- guard newValue != state. propertiesURL [ MetatypeWrapper ( P . self) ] else {
201
- return nil
212
+ mutateObservation ( of: ProgressManager . additionalPropertiesKeyPath. withLock { $0 } ) {
213
+ let parents : [ ParentState ] ? = state. withLock { state in
214
+ guard newValue != state. propertiesURL [ MetatypeWrapper ( P . self) ] else {
215
+ return nil
216
+ }
217
+ state. propertiesURL [ MetatypeWrapper ( P . self) ] = newValue
218
+ return state. parents
219
+ }
220
+ if let parents = parents {
221
+ markSelfDirty ( property: MetatypeWrapper ( P . self) , parents: parents)
202
222
}
203
- state. propertiesURL [ MetatypeWrapper ( P . self) ] = newValue
204
- return state. parents
205
- }
206
- if let parents = parents {
207
- markSelfDirty ( property: MetatypeWrapper ( P . self) , parents: parents)
208
223
}
209
224
}
210
225
}
@@ -218,36 +233,39 @@ extension ProgressManager {
218
233
/// - Parameter key: A key path to the custom unsigned integer property type.
219
234
public subscript< P: Property > ( dynamicMember key: KeyPath < ProgressManager . Properties , P . Type > ) -> UInt64 where P. Value == UInt64 , P. Summary == [ UInt64 ] {
220
235
get {
221
- state. withLock { state in
236
+ accessObservation ( keyPath: ProgressManager . additionalPropertiesKeyPath. withLock { $0 } )
237
+ return state. withLock { state in
222
238
if P . self == ProgressManager . Properties. Throughput. self {
223
239
return state. throughput
224
240
} else {
225
- return state. propertiesUInt64Array [ MetatypeWrapper ( P . self) ] ?? P . self . defaultValue
241
+ return state. propertiesUInt64Array [ MetatypeWrapper ( P . self) ] ?? P . defaultValue
226
242
}
227
243
}
228
244
}
229
245
230
246
set {
231
- let parents : [ ParentState ] ? = state. withLock { state in
232
- if P . self == ProgressManager . Properties. Throughput. self {
233
- guard newValue != state. throughput else {
234
- return nil
235
- }
236
- state. throughput = newValue
237
- return state. parents
238
- } else {
239
- guard newValue != state. propertiesUInt64Array [ MetatypeWrapper ( P . self) ] else {
240
- return nil
247
+ mutateObservation ( of: ProgressManager . additionalPropertiesKeyPath. withLock { $0 } ) {
248
+ let parents : [ ParentState ] ? = state. withLock { state in
249
+ if P . self == ProgressManager . Properties. Throughput. self {
250
+ guard newValue != state. throughput else {
251
+ return nil
252
+ }
253
+ state. throughput = newValue
254
+ return state. parents
255
+ } else {
256
+ guard newValue != state. propertiesUInt64Array [ MetatypeWrapper ( P . self) ] else {
257
+ return nil
258
+ }
259
+ state. propertiesUInt64Array [ MetatypeWrapper ( P . self) ] = newValue
260
+ return state. parents
241
261
}
242
- state. propertiesUInt64Array [ MetatypeWrapper ( P . self) ] = newValue
243
- return state. parents
244
262
}
245
- }
246
- if let parents = parents {
247
- if P . self == ProgressManager . Properties. Throughput. self {
248
- markSelfDirty ( property : ProgressManager . Properties . Throughput . self , parents : parents )
249
- } else {
250
- markSelfDirty ( property : MetatypeWrapper ( P . self ) , parents : parents )
263
+ if let parents = parents {
264
+ if P . self == ProgressManager . Properties . Throughput . self {
265
+ markSelfDirty ( property : ProgressManager . Properties. Throughput. self, parents : parents )
266
+ } else {
267
+ markSelfDirty ( property : MetatypeWrapper ( P . self ) , parents : parents )
268
+ }
251
269
}
252
270
}
253
271
}
@@ -262,36 +280,39 @@ extension ProgressManager {
262
280
/// - Parameter key: A key path to the custom duration property type.
263
281
public subscript< P: Property > ( dynamicMember key: KeyPath < ProgressManager . Properties , P . Type > ) -> Duration where P. Value == Duration , P. Summary == Duration {
264
282
get {
265
- state. withLock { state in
283
+ accessObservation ( keyPath: ProgressManager . additionalPropertiesKeyPath. withLock { $0 } )
284
+ return state. withLock { state in
266
285
if P . self == ProgressManager . Properties. EstimatedTimeRemaining. self {
267
286
return state. estimatedTimeRemaining
268
287
} else {
269
- return state. propertiesDuration [ MetatypeWrapper ( P . self) ] ?? P . self . defaultValue
288
+ return state. propertiesDuration [ MetatypeWrapper ( P . self) ] ?? P . defaultValue
270
289
}
271
290
}
272
291
}
273
292
274
293
set {
275
- let parents : [ ParentState ] ? = state. withLock { state in
276
- if P . self == ProgressManager . Properties. EstimatedTimeRemaining. self {
277
- guard newValue != state. estimatedTimeRemaining else {
278
- return nil
294
+ mutateObservation ( of: ProgressManager . additionalPropertiesKeyPath. withLock { $0 } ) {
295
+ let parents : [ ParentState ] ? = state. withLock { state in
296
+ if P . self == ProgressManager . Properties. EstimatedTimeRemaining. self {
297
+ guard newValue != state. estimatedTimeRemaining else {
298
+ return nil
299
+ }
300
+ state. estimatedTimeRemaining = newValue
301
+ return state. parents
302
+ } else {
303
+ guard newValue != state. propertiesDuration [ MetatypeWrapper ( P . self) ] else {
304
+ return nil
305
+ }
306
+ state. propertiesDuration [ MetatypeWrapper ( P . self) ] = newValue
307
+ return state. parents
279
308
}
280
- state. estimatedTimeRemaining = newValue
281
- return state. parents
282
- } else {
283
- guard newValue != state. propertiesDuration [ MetatypeWrapper ( P . self) ] else {
284
- return nil
285
- }
286
- state. propertiesDuration [ MetatypeWrapper ( P . self) ] = newValue
287
- return state. parents
288
309
}
289
- }
290
- if let parents = parents {
291
- if P . self == ProgressManager . Properties. EstimatedTimeRemaining. self {
292
- markSelfDirty ( property : ProgressManager . Properties . EstimatedTimeRemaining . self , parents : parents )
293
- } else {
294
- markSelfDirty ( property : MetatypeWrapper ( P . self ) , parents : parents )
310
+ if let parents = parents {
311
+ if P . self == ProgressManager . Properties . EstimatedTimeRemaining . self {
312
+ markSelfDirty ( property : ProgressManager . Properties. EstimatedTimeRemaining. self, parents : parents )
313
+ } else {
314
+ markSelfDirty ( property : MetatypeWrapper ( P . self ) , parents : parents )
315
+ }
295
316
}
296
317
}
297
318
}
0 commit comments