@@ -16,9 +16,9 @@ import Observation
16
16
///
17
17
/// It is read-only and can be added as a child of another ProgressManager.
18
18
@available ( FoundationPreview 6 . 2 , * )
19
+ @dynamicMemberLookup
19
20
@Observable public final class ProgressReporter : Sendable , Hashable , Equatable , CustomStringConvertible , CustomDebugStringConvertible {
20
21
21
- public typealias Values = ProgressManager . Values
22
22
public typealias Property = ProgressManager . Property
23
23
24
24
/// The total units of work.
@@ -82,13 +82,6 @@ import Observation
82
82
return self . description
83
83
}
84
84
85
- /// Reads properties that convey additional information about progress.
86
- public func withProperties< T, E: Error > (
87
- _ closure: ( sending Values) throws ( E ) -> sending T
88
- ) throws ( E) -> T {
89
- return try manager. getProperties ( closure)
90
- }
91
-
92
85
/// Returns a summary for the specified integer property across the progress subtree.
93
86
///
94
87
/// This method aggregates the values of a custom integer property from the underlying progress manager
@@ -173,6 +166,97 @@ import Observation
173
166
return manager. summary ( of: property)
174
167
}
175
168
169
+ /// Gets or sets custom integer properties.
170
+ ///
171
+ /// This subscript provides read-write access to custom progress properties where both the value
172
+ /// and summary types are `Int`. If the property has not been set, the getter returns the
173
+ /// property's default value.
174
+ ///
175
+ /// - Parameter key: A key path to the custom integer property type.
176
+ public subscript< P: Property > ( dynamicMember key: KeyPath < ProgressManager . Properties , P . Type > ) -> Int where P. Value == Int , P. Summary == Int {
177
+ get {
178
+ manager [ dynamicMember: key]
179
+ }
180
+ }
181
+
182
+ /// Gets or sets custom unsigned integer properties.
183
+ ///
184
+ /// This subscript provides read-write access to custom progress properties where both the value
185
+ /// and summary types are `UInt64`. If the property has not been set, the getter returns the
186
+ /// property's default value.
187
+ ///
188
+ /// - Parameter key: A key path to the custom unsigned integer property type.
189
+ public subscript< P: Property > ( dynamicMember key: KeyPath < ProgressManager . Properties , P . Type > ) -> UInt64 where P. Value == UInt64 , P. Summary == UInt64 {
190
+ get {
191
+ manager [ dynamicMember: key]
192
+ }
193
+ }
194
+
195
+ /// Gets or sets custom double properties.
196
+ ///
197
+ /// This subscript provides read-write access to custom progress properties where both the value
198
+ /// and summary types are `Double`. If the property has not been set, the getter returns the
199
+ /// property's default value.
200
+ ///
201
+ /// - Parameter key: A key path to the custom double property type.
202
+ public subscript< P: Property > ( dynamicMember key: KeyPath < ProgressManager . Properties , P . Type > ) -> P . Value where P. Value == Double , P. Summary == Double {
203
+ get {
204
+ manager [ dynamicMember: key]
205
+ }
206
+ }
207
+
208
+ /// Gets or sets custom string properties.
209
+ ///
210
+ /// This subscript provides read-write access to custom progress properties where the value
211
+ /// type is `String?` and the summary type is `[String?]`. If the property has not been set,
212
+ /// the getter returns the property's default value.
213
+ ///
214
+ /// - Parameter key: A key path to the custom string property type.
215
+ public subscript< P: Property > ( dynamicMember key: KeyPath < ProgressManager . Properties , P . Type > ) -> String ? where P. Value == String ? , P. Summary == [ String ? ] {
216
+ get {
217
+ manager [ dynamicMember: key]
218
+ }
219
+ }
220
+
221
+ /// Gets or sets custom URL properties.
222
+ ///
223
+ /// This subscript provides read-write access to custom progress properties where the value
224
+ /// type is `URL?` and the summary type is `[URL?]`. If the property has not been set,
225
+ /// the getter returns the property's default value.
226
+ ///
227
+ /// - Parameter key: A key path to the custom URL property type.
228
+ public subscript< P: Property > ( dynamicMember key: KeyPath < ProgressManager . Properties , P . Type > ) -> URL ? where P. Value == URL ? , P. Summary == [ URL ? ] {
229
+ get {
230
+ manager [ dynamicMember: key]
231
+ }
232
+ }
233
+
234
+ /// Gets or sets custom unsigned integer properties.
235
+ ///
236
+ /// This subscript provides read-write access to custom progress properties where the value
237
+ /// type is `UInt64` and the summary type is `[UInt64]`. If the property has not been set,
238
+ /// the getter returns the property's default value.
239
+ ///
240
+ /// - Parameter key: A key path to the custom unsigned integer property type.
241
+ public subscript< P: Property > ( dynamicMember key: KeyPath < ProgressManager . Properties , P . Type > ) -> UInt64 where P. Value == UInt64 , P. Summary == [ UInt64 ] {
242
+ get {
243
+ manager [ dynamicMember: key]
244
+ }
245
+ }
246
+
247
+ /// Gets or sets custom duration properties.
248
+ ///
249
+ /// This subscript provides read-write access to custom progress properties where the value
250
+ /// type is `Duration` and the summary type is `Duration`. If the property has not been set,
251
+ /// the getter returns the property's default value.
252
+ ///
253
+ /// - Parameter key: A key path to the custom duration property type.
254
+ public subscript< P: Property > ( dynamicMember key: KeyPath < ProgressManager . Properties , P . Type > ) -> Duration where P. Value == Duration , P. Summary == Duration {
255
+ get {
256
+ manager [ dynamicMember: key]
257
+ }
258
+ }
259
+
176
260
internal let manager : ProgressManager
177
261
178
262
internal init ( manager: ProgressManager ) {
0 commit comments