Skip to content

Commit dc7c753

Browse files
committed
adopt suggestion for using keypath instead of Property.Type as argument in summary methods
1 parent 1aac1b5 commit dc7c753

File tree

5 files changed

+118
-118
lines changed

5 files changed

+118
-118
lines changed

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

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -388,13 +388,13 @@ 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)
395395
self.didSet(keyPath: \.totalFileCountSummary)
396396
return updatedFileCount(type: .total)
397-
} else if property.self == ProgressManager.Properties.CompletedFileCount.self {
397+
} else if P.self == ProgressManager.Properties.CompletedFileCount.self {
398398
self.access(keyPath: \.completedFileCount)
399399
self.access(keyPath: \.completedFileCountSummary)
400400
self.didSet(keyPath: \.completedFileCountSummary)
@@ -403,7 +403,7 @@ extension ProgressManager {
403403
self.access(keyPath: \.customPropertiesInt)
404404
self.access(keyPath: \.customPropertiesIntSummary)
405405
self.didSet(keyPath: \.customPropertiesIntSummary)
406-
return updatedIntSummary(property: MetatypeWrapper(property))
406+
return updatedIntSummary(property: MetatypeWrapper(P.self))
407407
}
408408
}
409409

@@ -415,13 +415,13 @@ extension ProgressManager {
415415
/// - Parameter property: The type of the unsigned integer property to summarize. Must be a property
416416
/// where both the value and summary types are `UInt64`.
417417
/// - 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 {
418+
public func summary<P: Property>(of property: KeyPath<ProgressManager.Properties, P.Type>) -> P.Summary where P.Value == UInt64, P.Summary == UInt64 {
419+
if P.self == ProgressManager.Properties.TotalByteCount.self {
420420
self.access(keyPath: \.totalByteCount)
421421
self.access(keyPath: \.totalByteCountSummary)
422422
self.didSet(keyPath: \.totalByteCountSummary)
423423
return updatedByteCount(type: .total)
424-
} else if property.self == ProgressManager.Properties.CompletedByteCount.self {
424+
} else if P.self == ProgressManager.Properties.CompletedByteCount.self {
425425
self.access(keyPath: \.completedByteCount)
426426
self.access(keyPath: \.completedByteCountSummary)
427427
self.didSet(keyPath: \.completedByteCountSummary)
@@ -430,7 +430,7 @@ extension ProgressManager {
430430
self.access(keyPath: \.customPropertiesUInt64)
431431
self.access(keyPath: \.customPropertiesUInt64Summary)
432432
self.didSet(keyPath: \.customPropertiesUInt64Summary)
433-
return updatedUInt64Summary(property: MetatypeWrapper(property))
433+
return updatedUInt64Summary(property: MetatypeWrapper(P.self))
434434
}
435435
}
436436

@@ -442,11 +442,11 @@ extension ProgressManager {
442442
/// - Parameter property: The type of the double property to summarize. Must be a property
443443
/// where both the value and summary types are `Double`.
444444
/// - 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 {
445+
public func summary<P: Property>(of property: KeyPath<ProgressManager.Properties, P.Type>) -> P.Summary where P.Value == Double, P.Summary == Double {
446446
self.access(keyPath: \.customPropertiesDouble)
447447
self.access(keyPath: \.customPropertiesDoubleSummary)
448448
self.didSet(keyPath: \.customPropertiesDoubleSummary)
449-
return updatedDoubleSummary(property: MetatypeWrapper(property))
449+
return updatedDoubleSummary(property: MetatypeWrapper(P.self))
450450
}
451451

452452
/// Returns a summary for a custom string property across the progress subtree.
@@ -457,11 +457,11 @@ extension ProgressManager {
457457
/// - Parameter property: The type of the string property to summarize. Must be a property
458458
/// where both the value type is `String?` and the summary type is `[String?]`.
459459
/// - 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?] {
460+
public func summary<P: Property>(of property: KeyPath<ProgressManager.Properties, P.Type>) -> P.Summary where P.Value == String?, P.Summary == [String?] {
461461
self.access(keyPath: \.customPropertiesString)
462462
self.access(keyPath: \.customPropertiesStringSummary)
463463
self.didSet(keyPath: \.customPropertiesStringSummary)
464-
return updatedStringSummary(property: MetatypeWrapper(property))
464+
return updatedStringSummary(property: MetatypeWrapper(P.self))
465465
}
466466

467467
/// Returns a summary for a custom URL property across the progress subtree.
@@ -472,11 +472,11 @@ extension ProgressManager {
472472
/// - Parameter property: The type of the URL property to summarize. Must be a property
473473
/// where the value type is `URL?` and the summary type is `[URL?]`.
474474
/// - 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?] {
475+
public func summary<P: Property>(of property: KeyPath<ProgressManager.Properties, P.Type>) -> P.Summary where P.Value == URL?, P.Summary == [URL?] {
476476
self.access(keyPath: \.customPropertiesURL)
477477
self.access(keyPath: \.customPropertiesURLSummary)
478478
self.didSet(keyPath: \.customPropertiesURLSummary)
479-
return updatedURLSummary(property: MetatypeWrapper(property))
479+
return updatedURLSummary(property: MetatypeWrapper(P.self))
480480
}
481481

482482
/// Returns a summary for a custom unsigned integer property across the progress subtree.
@@ -487,8 +487,8 @@ extension ProgressManager {
487487
/// - Parameter property: The type of the unsigned integer property to summarize. Must be a property
488488
/// where the value type is `UInt64` and the summary type is `[UInt64]`.
489489
/// - 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 {
490+
public func summary<P: Property>(of property: KeyPath<ProgressManager.Properties, P.Type>) -> P.Summary where P.Value == UInt64, P.Summary == [UInt64] {
491+
if P.self == ProgressManager.Properties.Throughput.self {
492492
self.access(keyPath: \.throughput)
493493
self.access(keyPath: \.throughputSummary)
494494
self.didSet(keyPath: \.throughputSummary)
@@ -497,7 +497,7 @@ extension ProgressManager {
497497
self.access(keyPath: \.customPropertiesUInt64Array)
498498
self.access(keyPath: \.customPropertiesUInt64ArraySummary)
499499
self.didSet(keyPath: \.customPropertiesUInt64ArraySummary)
500-
return updatedUInt64ArraySummary(property: MetatypeWrapper(property))
500+
return updatedUInt64ArraySummary(property: MetatypeWrapper(P.self))
501501
}
502502
}
503503

@@ -509,8 +509,8 @@ extension ProgressManager {
509509
/// - Parameter property: The type of the duration property to summarize. Must be a property
510510
/// where the value type is `Duration` and the summary type is `Duration`.
511511
/// - 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 {
512+
public func summary<P: Property>(of property: KeyPath<ProgressManager.Properties, P.Type>) -> P.Summary where P.Value == Duration, P.Summary == Duration {
513+
if P.self == ProgressManager.Properties.EstimatedTimeRemaining.self {
514514
self.access(keyPath: \.estimatedTimeRemaining)
515515
self.access(keyPath: \.estimatedTimeRemainingSummary)
516516
self.didSet(keyPath: \.estimatedTimeRemainingSummary)
@@ -519,7 +519,7 @@ extension ProgressManager {
519519
self.access(keyPath: \.customPropertiesDuration)
520520
self.access(keyPath: \.customPropertiesDurationSummary)
521521
self.didSet(keyPath: \.customPropertiesDurationSummary)
522-
return updatedDurationSummary(property: MetatypeWrapper(property))
522+
return updatedDurationSummary(property: MetatypeWrapper(P.self))
523523
}
524524
}
525525
}

Sources/FoundationEssentials/ProgressManager/ProgressManager.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -551,12 +551,12 @@ extension ProgressManager: CustomStringConvertible, CustomDebugStringConvertible
551551
fractionCompleted: \(fractionCompleted)
552552
isIndeterminate: \(isIndeterminate)
553553
isFinished: \(isFinished)
554-
totalFileCount: \(summary(of: ProgressManager.Properties.TotalFileCount.self))
555-
completedFileCount: \(summary(of: ProgressManager.Properties.CompletedFileCount.self))
556-
totalByteCount: \(summary(of: ProgressManager.Properties.TotalByteCount.self))
557-
completedByteCount: \(summary(of: ProgressManager.Properties.CompletedByteCount.self))
558-
throughput: \(summary(of: ProgressManager.Properties.Throughput.self))
559-
estimatedTimeRemaining: \(summary(of: ProgressManager.Properties.EstimatedTimeRemaining.self))
554+
totalFileCount: \(summary(of: \.totalFileCount))
555+
completedFileCount: \(summary(of: \.completedFileCount))
556+
totalByteCount: \(summary(of: \.totalByteCount))
557+
completedByteCount: \(summary(of: \.completedByteCount))
558+
throughput: \(summary(of: \.throughput))
559+
estimatedTimeRemaining: \(summary(of: \.estimatedTimeRemaining))
560560
"""
561561
}
562562

Sources/FoundationEssentials/ProgressManager/ProgressReporter.swift

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,12 @@ import Observation
6565
fractionCompleted: \(fractionCompleted)
6666
isIndeterminate: \(isIndeterminate)
6767
isFinished: \(isFinished)
68-
totalFileCount: \(summary(of: ProgressManager.Properties.TotalFileCount.self))
69-
completedFileCount: \(summary(of: ProgressManager.Properties.CompletedFileCount.self))
70-
totalByteCount: \(summary(of: ProgressManager.Properties.TotalByteCount.self))
71-
completedByteCount: \(summary(of: ProgressManager.Properties.CompletedByteCount.self))
72-
throughput: \(summary(of: ProgressManager.Properties.Throughput.self))
73-
estimatedTimeRemaining: \(summary(of: ProgressManager.Properties.EstimatedTimeRemaining.self))
68+
totalFileCount: \(summary(of: \.totalFileCount))
69+
completedFileCount: \(summary(of: \.completedFileCount))
70+
totalByteCount: \(summary(of: \.totalByteCount))
71+
completedByteCount: \(summary(of: \.completedByteCount))
72+
throughput: \(summary(of: \.throughput))
73+
estimatedTimeRemaining: \(summary(of: \.estimatedTimeRemaining))
7474
"""
7575
}
7676

@@ -90,7 +90,7 @@ import Observation
9090
/// - Parameter property: The type of the integer property to summarize. Must be a property
9191
/// where both the value and summary types are `Int`.
9292
/// - Returns: The aggregated summary value for the specified property across the entire subtree.
93-
public func summary<P: Property>(of property: P.Type) -> Int where P.Value == Int, P.Summary == Int {
93+
public func summary<P: Property>(of property: KeyPath<ProgressManager.Properties, P.Type>) -> Int where P.Value == Int, P.Summary == Int {
9494
manager.summary(of: property)
9595
}
9696

@@ -102,7 +102,7 @@ import Observation
102102
/// - Parameter property: The type of the unsigned property to summarize. Must be a property
103103
/// where both the value and summary types are `UInt64`.
104104
/// - Returns: The aggregated summary value for the specified property across the entire subtree.
105-
public func summary<P: Property>(of property: P.Type) -> UInt64 where P.Value == UInt64, P.Summary == UInt64 {
105+
public func summary<P: Property>(of property: KeyPath<ProgressManager.Properties, P.Type>) -> UInt64 where P.Value == UInt64, P.Summary == UInt64 {
106106
manager.summary(of: property)
107107
}
108108

@@ -114,7 +114,7 @@ import Observation
114114
/// - Parameter property: The type of the double property to summarize. Must be a property
115115
/// where both the value and summary types are `Double`.
116116
/// - Returns: The aggregated summary value for the specified property across the entire subtree.
117-
public func summary<P: Property>(of property: P.Type) -> Double where P.Value == Double, P.Summary == Double {
117+
public func summary<P: Property>(of property: KeyPath<ProgressManager.Properties, P.Type>) -> Double where P.Value == Double, P.Summary == Double {
118118
manager.summary(of: property)
119119
}
120120

@@ -126,7 +126,7 @@ import Observation
126126
/// - Parameter property: The type of the string property to summarize. Must be a property
127127
/// where both the value and summary types are `String`.
128128
/// - Returns: The aggregated summary value for the specified property across the entire subtree.
129-
public func summary<P: Property>(of property: P.Type) -> [String?] where P.Value == String?, P.Summary == [String?] {
129+
public func summary<P: Property>(of property: KeyPath<ProgressManager.Properties, P.Type>) -> [String?] where P.Value == String?, P.Summary == [String?] {
130130
return manager.summary(of: property)
131131
}
132132

@@ -138,7 +138,7 @@ import Observation
138138
/// - Parameter property: The type of the URL property to summarize. Must be a property
139139
/// where both the value and summary types are `URL?` and `[URL?]` respectively.
140140
/// - Returns: The aggregated summary value for the specified property across the entire subtree.
141-
public func summary<P: Property>(of property: P.Type) -> [URL?] where P.Value == URL?, P.Summary == [URL?] {
141+
public func summary<P: Property>(of property: KeyPath<ProgressManager.Properties, P.Type>) -> [URL?] where P.Value == URL?, P.Summary == [URL?] {
142142
return manager.summary(of: property)
143143
}
144144

@@ -150,7 +150,7 @@ import Observation
150150
/// - Parameter property: The type of the unsigned integer property to summarize. Must be a property
151151
/// where the value type is `UInt64` and the summary type is `[UInt64]`.
152152
/// - Returns: The aggregated summary value for the specified property across the entire subtree.
153-
public func summary<P: Property>(of property: P.Type) -> [UInt64] where P.Value == UInt64, P.Summary == [UInt64] {
153+
public func summary<P: Property>(of property: KeyPath<ProgressManager.Properties, P.Type>) -> [UInt64] where P.Value == UInt64, P.Summary == [UInt64] {
154154
return manager.summary(of: property)
155155
}
156156

@@ -162,7 +162,7 @@ import Observation
162162
/// - Parameter property: The type of the duration property to summarize. Must be a property
163163
/// where both the value and summary types are `Duration`.
164164
/// - Returns: The aggregated summary value for the specified property across the entire subtree.
165-
public func summary<P: Property>(of property: P.Type) -> Duration where P.Value == Duration, P.Summary == Duration {
165+
public func summary<P: Property>(of property: KeyPath<ProgressManager.Properties, P.Type>) -> Duration where P.Value == Duration, P.Summary == Duration {
166166
return manager.summary(of: property)
167167
}
168168

0 commit comments

Comments
 (0)