Skip to content

Commit f819caa

Browse files
authored
Minor Updates to ProgressManager API (#1559)
* adopt suggestion for using keypath instead of Property.Type as argument in summary methods * rename interop methods based on api-central review * fix calling order of didSet correct calling order of didSet add missing case * rename helper methods to use update instead of updated
1 parent 6aa02a0 commit f819caa

File tree

9 files changed

+171
-158
lines changed

9 files changed

+171
-158
lines changed

Sources/FoundationEssentials/ProgressManager/ProgressManager+Interop.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ extension Progress {
2828
/// - Parameter count: Number of units delegated to a child instance of `ProgressManager`
2929
/// which may be instantiated by `Subprogress` later when `reporter(totalCount:)` is called.
3030
/// - Returns: A `Subprogress` instance.
31-
public func makeChild(withPendingUnitCount count: Int) -> Subprogress {
31+
public func subprogress(assigningCount count: Int) -> Subprogress {
3232

3333
// Make a ProgressManager
3434
let manager = ProgressManager(totalCount: 1)
@@ -102,7 +102,7 @@ extension ProgressManager {
102102
/// - Parameters:
103103
/// - count: Number of units delegated from `self`'s `totalCount`.
104104
/// - progress: `Progress` which receives the delegated `count`.
105-
public func subprogress(assigningCount count: Int, to progress: Foundation.Progress) {
105+
public func assign(count: Int, to progress: Foundation.Progress) {
106106
precondition(progress._parent() == nil, "Cannot assign a progress to more than one parent.")
107107

108108
// Create a ProgressManager - NSProgress bridge

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

Lines changed: 39 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -388,22 +388,25 @@ extension ProgressManager {
388388
/// - Parameter property: The type of the integer property to summarize. Must be a property
389389
/// where both the value and summary types are `Int`.
390390
/// - Returns: An `Int` summary value for the specified property.
391-
public func summary<P: Property>(of property: P.Type) -> P.Summary where P.Value == Int, P.Summary == Int {
392-
if property.self == ProgressManager.Properties.TotalFileCount.self {
391+
public func summary<P: Property>(of property: KeyPath<ProgressManager.Properties, P.Type>) -> P.Summary where P.Value == Int, P.Summary == Int {
392+
if P.self == ProgressManager.Properties.TotalFileCount.self {
393393
self.access(keyPath: \.totalFileCount)
394394
self.access(keyPath: \.totalFileCountSummary)
395+
let updatedFileCount = updateFileCount(type: .total)
395396
self.didSet(keyPath: \.totalFileCountSummary)
396-
return updatedFileCount(type: .total)
397-
} else if property.self == ProgressManager.Properties.CompletedFileCount.self {
397+
return updatedFileCount
398+
} else if P.self == ProgressManager.Properties.CompletedFileCount.self {
398399
self.access(keyPath: \.completedFileCount)
399400
self.access(keyPath: \.completedFileCountSummary)
401+
let updatedFileCount = updateFileCount(type: .completed)
400402
self.didSet(keyPath: \.completedFileCountSummary)
401-
return updatedFileCount(type: .completed)
403+
return updatedFileCount
402404
} else {
403405
self.access(keyPath: \.customPropertiesInt)
404406
self.access(keyPath: \.customPropertiesIntSummary)
407+
let updatedResult = updateIntSummary(property: MetatypeWrapper(P.self))
405408
self.didSet(keyPath: \.customPropertiesIntSummary)
406-
return updatedIntSummary(property: MetatypeWrapper(property))
409+
return updatedResult
407410
}
408411
}
409412

@@ -415,22 +418,25 @@ extension ProgressManager {
415418
/// - Parameter property: The type of the unsigned integer property to summarize. Must be a property
416419
/// where both the value and summary types are `UInt64`.
417420
/// - Returns: An `UInt64` summary value for the specified property.
418-
public func summary<P: Property>(of property: P.Type) -> P.Summary where P.Value == UInt64, P.Summary == UInt64 {
419-
if property.self == ProgressManager.Properties.TotalByteCount.self {
421+
public func summary<P: Property>(of property: KeyPath<ProgressManager.Properties, P.Type>) -> P.Summary where P.Value == UInt64, P.Summary == UInt64 {
422+
if P.self == ProgressManager.Properties.TotalByteCount.self {
420423
self.access(keyPath: \.totalByteCount)
421424
self.access(keyPath: \.totalByteCountSummary)
425+
let updatedByteCount = updateByteCount(type: .total)
422426
self.didSet(keyPath: \.totalByteCountSummary)
423-
return updatedByteCount(type: .total)
424-
} else if property.self == ProgressManager.Properties.CompletedByteCount.self {
427+
return updatedByteCount
428+
} else if P.self == ProgressManager.Properties.CompletedByteCount.self {
425429
self.access(keyPath: \.completedByteCount)
426430
self.access(keyPath: \.completedByteCountSummary)
431+
let updatedByteCount = updateByteCount(type: .completed)
427432
self.didSet(keyPath: \.completedByteCountSummary)
428-
return updatedByteCount(type: .completed)
433+
return updatedByteCount
429434
} else {
430435
self.access(keyPath: \.customPropertiesUInt64)
431436
self.access(keyPath: \.customPropertiesUInt64Summary)
437+
let updatedResult = updateUInt64Summary(property: MetatypeWrapper(P.self))
432438
self.didSet(keyPath: \.customPropertiesUInt64Summary)
433-
return updatedUInt64Summary(property: MetatypeWrapper(property))
439+
return updatedResult
434440
}
435441
}
436442

@@ -442,11 +448,12 @@ extension ProgressManager {
442448
/// - Parameter property: The type of the double property to summarize. Must be a property
443449
/// where both the value and summary types are `Double`.
444450
/// - Returns: A `Double` summary value for the specified property.
445-
public func summary<P: Property>(of property: P.Type) -> P.Summary where P.Value == Double, P.Summary == Double {
451+
public func summary<P: Property>(of property: KeyPath<ProgressManager.Properties, P.Type>) -> P.Summary where P.Value == Double, P.Summary == Double {
446452
self.access(keyPath: \.customPropertiesDouble)
447453
self.access(keyPath: \.customPropertiesDoubleSummary)
454+
let updatedResult = updateDoubleSummary(property: MetatypeWrapper(P.self))
448455
self.didSet(keyPath: \.customPropertiesDoubleSummary)
449-
return updatedDoubleSummary(property: MetatypeWrapper(property))
456+
return updatedResult
450457
}
451458

452459
/// Returns a summary for a custom string property across the progress subtree.
@@ -457,11 +464,12 @@ extension ProgressManager {
457464
/// - Parameter property: The type of the string property to summarize. Must be a property
458465
/// where both the value type is `String?` and the summary type is `[String?]`.
459466
/// - Returns: A `[String?]` summary value for the specified property.
460-
public func summary<P: Property>(of property: P.Type) -> P.Summary where P.Value == String?, P.Summary == [String?] {
467+
public func summary<P: Property>(of property: KeyPath<ProgressManager.Properties, P.Type>) -> P.Summary where P.Value == String?, P.Summary == [String?] {
461468
self.access(keyPath: \.customPropertiesString)
462469
self.access(keyPath: \.customPropertiesStringSummary)
470+
let updatedResult = updateStringSummary(property: MetatypeWrapper(P.self))
463471
self.didSet(keyPath: \.customPropertiesStringSummary)
464-
return updatedStringSummary(property: MetatypeWrapper(property))
472+
return updatedResult
465473
}
466474

467475
/// Returns a summary for a custom URL property across the progress subtree.
@@ -472,11 +480,12 @@ extension ProgressManager {
472480
/// - Parameter property: The type of the URL property to summarize. Must be a property
473481
/// where the value type is `URL?` and the summary type is `[URL?]`.
474482
/// - Returns: A `[URL?]` summary value for the specified property.
475-
public func summary<P: Property>(of property: P.Type) -> P.Summary where P.Value == URL?, P.Summary == [URL?] {
483+
public func summary<P: Property>(of property: KeyPath<ProgressManager.Properties, P.Type>) -> P.Summary where P.Value == URL?, P.Summary == [URL?] {
476484
self.access(keyPath: \.customPropertiesURL)
477485
self.access(keyPath: \.customPropertiesURLSummary)
486+
let updatedResult = updateURLSummary(property: MetatypeWrapper(P.self))
478487
self.didSet(keyPath: \.customPropertiesURLSummary)
479-
return updatedURLSummary(property: MetatypeWrapper(property))
488+
return updatedResult
480489
}
481490

482491
/// Returns a summary for a custom unsigned integer property across the progress subtree.
@@ -487,17 +496,19 @@ extension ProgressManager {
487496
/// - Parameter property: The type of the unsigned integer property to summarize. Must be a property
488497
/// where the value type is `UInt64` and the summary type is `[UInt64]`.
489498
/// - Returns: A `[UInt64]` summary value for the specified property.
490-
public func summary<P: Property>(of property: P.Type) -> P.Summary where P.Value == UInt64, P.Summary == [UInt64] {
491-
if property.self == ProgressManager.Properties.Throughput.self {
499+
public func summary<P: Property>(of property: KeyPath<ProgressManager.Properties, P.Type>) -> P.Summary where P.Value == UInt64, P.Summary == [UInt64] {
500+
if P.self == ProgressManager.Properties.Throughput.self {
492501
self.access(keyPath: \.throughput)
493502
self.access(keyPath: \.throughputSummary)
503+
let updatedThroughput = updateThroughput()
494504
self.didSet(keyPath: \.throughputSummary)
495-
return updatedThroughput()
505+
return updatedThroughput
496506
} else {
497507
self.access(keyPath: \.customPropertiesUInt64Array)
498508
self.access(keyPath: \.customPropertiesUInt64ArraySummary)
509+
let updatedResult = updateUInt64ArraySummary(property: MetatypeWrapper(P.self))
499510
self.didSet(keyPath: \.customPropertiesUInt64ArraySummary)
500-
return updatedUInt64ArraySummary(property: MetatypeWrapper(property))
511+
return updatedResult
501512
}
502513
}
503514

@@ -509,17 +520,19 @@ extension ProgressManager {
509520
/// - Parameter property: The type of the duration property to summarize. Must be a property
510521
/// where the value type is `Duration` and the summary type is `Duration`.
511522
/// - Returns: A `Duration` summary value for the specified property.
512-
public func summary<P: Property>(of property: P.Type) -> P.Summary where P.Value == Duration, P.Summary == Duration {
513-
if property.self == ProgressManager.Properties.EstimatedTimeRemaining.self {
523+
public func summary<P: Property>(of property: KeyPath<ProgressManager.Properties, P.Type>) -> P.Summary where P.Value == Duration, P.Summary == Duration {
524+
if P.self == ProgressManager.Properties.EstimatedTimeRemaining.self {
514525
self.access(keyPath: \.estimatedTimeRemaining)
515526
self.access(keyPath: \.estimatedTimeRemainingSummary)
527+
let updatedTimeRemaining = updateEstimatedTimeRemaining()
516528
self.didSet(keyPath: \.estimatedTimeRemainingSummary)
517-
return updatedEstimatedTimeRemaining()
529+
return updatedTimeRemaining
518530
} else {
519531
self.access(keyPath: \.customPropertiesDuration)
520532
self.access(keyPath: \.customPropertiesDurationSummary)
533+
let updatedResult = updateDurationSummary(property: MetatypeWrapper(P.self))
521534
self.didSet(keyPath: \.customPropertiesDurationSummary)
522-
return updatedDurationSummary(property: MetatypeWrapper(property))
535+
return updatedResult
523536
}
524537
}
525538
}

0 commit comments

Comments
 (0)