Skip to content

Commit 18f4405

Browse files
committed
update documentation for additional properties methods
1 parent 28d8265 commit 18f4405

File tree

3 files changed

+89
-36
lines changed

3 files changed

+89
-36
lines changed

Sources/FoundationEssentials/ProgressManager/ProgressManager+Properties+Accessors.swift

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -382,9 +382,9 @@ extension ProgressManager {
382382

383383
/// Gets or sets custom string properties.
384384
///
385-
/// This subscript provides read-write access to custom progress properties where both the value
386-
/// and summary types are `String`. If the property has not een set, the getter returns the
387-
/// property's default value.
385+
/// This subscript provides read-write access to custom progress properties where the value
386+
/// type is `String?` and the summary type is `[String?]`. If the property has not been set,
387+
/// the getter returns the property's default value.
388388
///
389389
/// - Parameter key: A key path to the custom string property type.
390390
public subscript<P: Property>(dynamicMember key: KeyPath<ProgressManager.Properties, P.Type>) -> String? where P.Value == String?, P.Summary == [String?] {
@@ -403,6 +403,13 @@ extension ProgressManager {
403403
}
404404
}
405405

406+
/// Gets or sets custom URL properties.
407+
///
408+
/// This subscript provides read-write access to custom progress properties where the value
409+
/// type is `URL?` and the summary type is `[URL?]`. If the property has not been set,
410+
/// the getter returns the property's default value.
411+
///
412+
/// - Parameter key: A key path to the custom URL property type.
406413
public subscript<P: Property>(dynamicMember key: KeyPath<ProgressManager.Properties, P.Type>) -> URL? where P.Value == URL?, P.Summary == [URL?] {
407414
get {
408415
return state.propertiesURL[MetatypeWrapper(P.self)] ?? P.self.defaultValue
@@ -419,6 +426,13 @@ extension ProgressManager {
419426
}
420427
}
421428

429+
/// Gets or sets custom UInt64 properties.
430+
///
431+
/// This subscript provides read-write access to custom progress properties where the value
432+
/// type is `UInt64` and the summary type is `[UInt64]`. If the property has not been set,
433+
/// the getter returns the property's default value.
434+
///
435+
/// - Parameter key: A key path to the custom UInt64 property type.
422436
public subscript<P: Property>(dynamicMember key: KeyPath<ProgressManager.Properties, P.Type>) -> UInt64? where P.Value == UInt64, P.Summary == [UInt64] {
423437
get {
424438
return state.propertiesUInt64[MetatypeWrapper(P.self)] ?? P.self.defaultValue
@@ -462,46 +476,62 @@ extension ProgressManager {
462476

463477
// MARK: Methods to Read Additional Properties of Subtree with ProgressManager as root
464478

465-
/// Returns a summary for the specified integer property across the progress subtree.
479+
/// Returns a summary for a custom integer property across the progress subtree.
466480
///
467481
/// This method aggregates the values of a custom integer property from this progress manager
468482
/// and all its children, returning a consolidated summary value.
469483
///
470484
/// - Parameter property: The type of the integer property to summarize. Must be a property
471485
/// where both the value and summary types are `Int`.
472-
/// - Returns: The aggregated summary value for the specified property across the entire subtree.
486+
/// - Returns: An `Int` summary value for the specified property.
473487
public func summary<P: Property>(of property: P.Type) -> P.Summary where P.Value == Int, P.Summary == Int {
474488
return getUpdatedIntSummary(property: MetatypeWrapper(property))
475489
}
476490

477-
/// Returns a summary for the specified double property across the progress subtree.
491+
/// Returns a summary for a custom double property across the progress subtree.
478492
///
479493
/// This method aggregates the values of a custom double property from this progress manager
480494
/// and all its children, returning a consolidated summary value.
481495
///
482496
/// - Parameter property: The type of the double property to summarize. Must be a property
483497
/// where both the value and summary types are `Double`.
484-
/// - Returns: The aggregated summary value for the specified property across the entire subtree.
498+
/// - Returns: A `Double` summary value for the specified property.
485499
public func summary<P: Property>(of property: P.Type) -> P.Summary where P.Value == Double, P.Summary == Double {
486500
return getUpdatedDoubleSummary(property: MetatypeWrapper(property))
487501
}
488502

489-
/// Returns a summary for the specified string property across the progress subtree.
503+
/// Returns a summary for a custom string property across the progress subtree.
490504
///
491505
/// This method aggregates the values of a custom string property from this progress manager
492506
/// and all its children, returning a consolidated summary value.
493507
///
494508
/// - Parameter property: The type of the string property to summarize. Must be a property
495-
/// where both the value and summary types are `String`.
496-
/// - Returns: The aggregated summary value for the specified property across the entire subtree.
509+
/// where both the value type is `String?` and the summary type is `[String?]`.
510+
/// - Returns: A `[String?]` summary value for the specified property.
497511
public func summary<P: Property>(of property: P.Type) -> P.Summary where P.Value == String?, P.Summary == [String?] {
498512
return getUpdatedStringSummary(property: MetatypeWrapper(property))
499513
}
500514

515+
/// Returns a summary for a custom URL property across the progress subtree.
516+
///
517+
/// This method aggregates the values of a custom URL property from this progress manager
518+
/// and all its children, returning a consolidated summary value as an array of URLs.
519+
///
520+
/// - Parameter property: The type of the URL property to summarize. Must be a property
521+
/// where the value type is `URL?` and the summary type is `[URL?]`.
522+
/// - Returns: A `[URL?]` summary value for the specified property.
501523
public func summary<P: Property>(of property: P.Type) -> P.Summary where P.Value == URL?, P.Summary == [URL?] {
502524
return getUpdatedURLSummary(property: MetatypeWrapper(property))
503525
}
504526

527+
/// Returns a summary for a custom UInt64 property across the progress subtree.
528+
///
529+
/// This method aggregates the values of a custom UInt64 property from this progress manager
530+
/// and all its children, returning a consolidated summary value as an array of UInt64 values.
531+
///
532+
/// - Parameter property: The type of the UInt64 property to summarize. Must be a property
533+
/// where the value type is `UInt64` and the summary type is `[UInt64]`.
534+
/// - Returns: A `[UInt64]` summary value for the specified property.
505535
public func summary<P: Property>(of property: P.Type) -> P.Summary where P.Value == UInt64, P.Summary == [UInt64] {
506536
return getUpdatedUInt64Summary(property: MetatypeWrapper(property))
507537
}

Sources/FoundationEssentials/ProgressManager/ProgressManager+Properties+Definitions.swift

Lines changed: 40 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,25 @@
1313
@available(FoundationPreview 6.2, *)
1414
extension ProgressManager {
1515

16-
/// A type that conveys task-specific information on progress.
16+
/// A type that conveys additional task-specific information on progress.
1717
///
1818
/// The `Property` protocol defines custom properties that can be associated with progress tracking.
19-
/// These properties allow you to store and aggregate additional information alongside the standard
20-
/// progress metrics like completion counts and file counts.
21-
///
22-
/// Properties use a key-value system where the key uniquely identifies the property type,
23-
/// and values can be aggregated across progress manager hierarchies through reduction and merging operations.
19+
/// These properties allow you to store and aggregate additional information alongside the
20+
/// standard progress metrics such as `totalCount` and `completedCount`.
2421
public protocol Property: SendableMetatype {
2522

26-
/// The type of individual values stored in this property.
23+
/// The type used for individual values of this property.
2724
///
28-
/// This associated type represents the data type of individual property values
25+
/// This associated type represents the type of property values
2926
/// that can be set on progress managers. Must be `Sendable` and `Equatable`.
27+
/// The currently allowed types are `Int`, `Double`, `String?`, `URL?` or `UInt64`.
3028
associatedtype Value: Sendable, Equatable
3129

3230
/// The type used for aggregated summaries of this property.
3331
///
34-
/// This associated type represents the data type used when summarizing property values
35-
/// across multiple progress managers in a hierarchy. Must be `Sendable` and `Equatable`.
32+
/// This associated type represents the type used when summarizing property values
33+
/// across multiple progress managers in a subtree.
34+
/// The currently allowed types are `Int`, `Double`, `[String?]`, `[URL?]` or `[UInt64]`.
3635
associatedtype Summary: Sendable, Equatable
3736

3837
/// A unique identifier for this property type.
@@ -54,7 +53,7 @@ extension ProgressManager {
5453
/// The default summary value for this property type.
5554
///
5655
/// This value is used as the initial summary when no property values have been
57-
/// aggregated yet, or as a fallback when summarization fails.
56+
/// aggregated yet.
5857
///
5958
/// - Returns: The default summary value for this property type.
6059
static var defaultSummary: Summary { get }
@@ -80,8 +79,24 @@ extension ProgressManager {
8079
/// - Returns: A new summary that represents the combination of both input summaries.
8180
static func merge(_ summary1: Summary, _ summary2: Summary) -> Summary
8281

83-
/// Determines the behavior for handling childSummary when the child is deinitialized.
84-
static func terminate(_ parentSummary: Summary, _ childSummary: Summary) -> Summary
82+
/// Determines how to handle summary data when a progress manager is deinitialized.
83+
///
84+
/// This method is used when a progress manager in the hierarchy is being
85+
/// deinitialized and its accumulated summary needs to be processed in relation to
86+
/// its parent's summary. The behavior can vary depending on the property type:
87+
///
88+
/// - For additive properties (like file counts, byte counts): The self summary
89+
/// is typically added to the parent summary to preserve the accumulated progress.
90+
/// - For max-based properties (like estimated time remaining): The parent summary
91+
/// is typically preserved as it represents an existing estimate.
92+
/// - For collection-based properties (like file URLs): The self summary may be
93+
/// discarded to avoid accumulating stale references.
94+
///
95+
/// - Parameters:
96+
/// - parentSummary: The current summary value of the parent progress manager.
97+
/// - selfSummary: The final summary value from the progress manager being deinitialized.
98+
/// - Returns: The updated summary that replaces the parent's current summary.
99+
static func terminate(_ parentSummary: Summary, _ selfSummary: Summary) -> Summary
85100
}
86101

87102
// Namespace for properties specific to operations reported on
@@ -109,8 +124,8 @@ extension ProgressManager {
109124
return summary1 + summary2
110125
}
111126

112-
public static func terminate(_ parentSummary: Int, _ childSummary: Int) -> Int {
113-
return parentSummary + childSummary
127+
public static func terminate(_ parentSummary: Int, _ selfSummary: Int) -> Int {
128+
return parentSummary + selfSummary
114129
}
115130
}
116131

@@ -136,8 +151,8 @@ extension ProgressManager {
136151
return summary1 + summary2
137152
}
138153

139-
public static func terminate(_ parentSummary: Int, _ childSummary: Int) -> Int {
140-
return parentSummary + childSummary
154+
public static func terminate(_ parentSummary: Int, _ selfSummary: Int) -> Int {
155+
return parentSummary + selfSummary
141156
}
142157
}
143158

@@ -163,8 +178,8 @@ extension ProgressManager {
163178
return summary1 + summary2
164179
}
165180

166-
public static func terminate(_ parentSummary: UInt64, _ childSummary: UInt64) -> UInt64 {
167-
return parentSummary + childSummary
181+
public static func terminate(_ parentSummary: UInt64, _ selfSummary: UInt64) -> UInt64 {
182+
return parentSummary + selfSummary
168183
}
169184
}
170185

@@ -190,8 +205,8 @@ extension ProgressManager {
190205
return summary1 + summary2
191206
}
192207

193-
public static func terminate(_ parentSummary: UInt64, _ childSummary: UInt64) -> UInt64 {
194-
return parentSummary + childSummary
208+
public static func terminate(_ parentSummary: UInt64, _ selfSummary: UInt64) -> UInt64 {
209+
return parentSummary + selfSummary
195210
}
196211
}
197212

@@ -216,8 +231,8 @@ extension ProgressManager {
216231
return summary1 + summary2
217232
}
218233

219-
public static func terminate(_ parentSummary: [UInt64], _ childSummary: [UInt64]) -> [UInt64] {
220-
return parentSummary + childSummary
234+
public static func terminate(_ parentSummary: [UInt64], _ selfSummary: [UInt64]) -> [UInt64] {
235+
return parentSummary + selfSummary
221236
}
222237
}
223238

@@ -247,7 +262,7 @@ extension ProgressManager {
247262
return max(summary1, summary2)
248263
}
249264

250-
public static func terminate(_ parentSummary: Duration, _ childSummary: Duration) -> Duration {
265+
public static func terminate(_ parentSummary: Duration, _ selfSummary: Duration) -> Duration {
251266
return parentSummary
252267
}
253268
}
@@ -278,7 +293,7 @@ extension ProgressManager {
278293
return summary1 + summary2
279294
}
280295

281-
public static func terminate(_ parentSummary: [URL?], _ childSummary: [URL?]) -> [URL?] {
296+
public static func terminate(_ parentSummary: [URL?], _ selfSummary: [URL?]) -> [URL?] {
282297
return parentSummary
283298
}
284299
}

Sources/FoundationEssentials/ProgressManager/ProgressReporter.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import Observation
1616
/// ProgressReporter is a wrapper for ProgressManager that carries information about ProgressManager.
1717
///
1818
/// It is read-only and can be added as a child of another ProgressManager.
19-
@Observable public final class ProgressReporter: Sendable, CustomStringConvertible, CustomDebugStringConvertible {
19+
@Observable public final class ProgressReporter: Sendable, Hashable, Equatable, CustomStringConvertible, CustomDebugStringConvertible {
2020

2121
/// The total units of work.
2222
public var totalCount: Int? {
@@ -183,4 +183,12 @@ import Observation
183183
internal init(manager: ProgressManager) {
184184
self.manager = manager
185185
}
186+
187+
public func hash(into hasher: inout Hasher) {
188+
hasher.combine(ObjectIdentifier(self))
189+
}
190+
191+
public static func == (lhs: ProgressReporter, rhs: ProgressReporter) -> Bool {
192+
ObjectIdentifier(lhs) == ObjectIdentifier(rhs)
193+
}
186194
}

0 commit comments

Comments
 (0)