Skip to content

Commit e2c875b

Browse files
committed
resolve build issues with ProgressReporter as API"
1 parent 8670f76 commit e2c875b

File tree

2 files changed

+50
-45
lines changed

2 files changed

+50
-45
lines changed

Sources/FoundationInternationalization/ProgressReporter/ProgressReporter+FileFormatStyle.swift

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ extension ProgressReporter.FileFormatStyle: FormatStyle {
5757
switch self.option.rawOption {
5858

5959
case .file:
60+
#if FOUNDATION_FRAMEWORK
6061
var fileCountLSR: LocalizedStringResource?
6162
var byteCountLSR: LocalizedStringResource?
6263
var throughputLSR: LocalizedStringResource?
@@ -88,6 +89,42 @@ extension ProgressReporter.FileFormatStyle: FormatStyle {
8889
\(String(localized: throughputLSR ?? ""))
8990
\(String(localized: timeRemainingLSR ?? ""))
9091
"""
92+
#else
93+
94+
var fileCountString: String?
95+
var byteCountString: String?
96+
var throughputString: String?
97+
var timeRemainingString: String?
98+
99+
let properties = reporter.withProperties(\.self)
100+
101+
if let totalFileCount = properties.totalFileCount {
102+
let completedFileCount = properties.completedFileCount ?? 0
103+
fileCountString = "\(completedFileCount.formatted(IntegerFormatStyle<Int>(locale: self.locale))) / \(totalFileCount.formatted(IntegerFormatStyle<Int>(locale: self.locale)))"
104+
}
105+
106+
if let totalByteCount = properties.totalByteCount {
107+
let completedByteCount = properties.completedByteCount ?? 0
108+
byteCountString = "\(completedByteCount.formatted(ByteCountFormatStyle(locale: self.locale))) / \(totalByteCount.formatted(ByteCountFormatStyle(locale: self.locale)))"
109+
}
110+
111+
if let throughput = properties.throughput {
112+
throughputString = "\(throughput.formatted(ByteCountFormatStyle(locale: self.locale)))/s"
113+
}
114+
115+
if let timeRemaining = properties.estimatedTimeRemaining {
116+
var formatStyle = Duration.UnitsFormatStyle(allowedUnits: [.hours, .minutes], width: .wide)
117+
formatStyle.locale = self.locale
118+
timeRemainingString = "\(timeRemaining.formatted(formatStyle)) remaining"
119+
}
120+
121+
return """
122+
\(fileCountString ?? "")
123+
\(byteCountString ?? "")
124+
\(throughputString ?? "")
125+
\(timeRemainingString ?? "")
126+
"""
127+
#endif
91128
}
92129
}
93130
}

Sources/FoundationInternationalization/ProgressReporter/ProgressReporter+FormatStyle.swift

Lines changed: 13 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,12 @@ extension ProgressReporter {
2121
// Outlines the options available to format ProgressReporter
2222
internal struct Option: Sendable, Codable, Hashable, Equatable {
2323

24-
#if FOUNDATION_FRAMEWORK
2524
/// Option specifying`fractionCompleted`.
2625
///
2726
/// For example, 20% completed.
2827
/// - Parameter style: A `FloatingPointFormatStyle<Double>.Percent` instance that should be used to format `fractionCompleted`.
2928
/// - Returns: A `LocalizedStringResource` for formatted `fractionCompleted`.
30-
internal static func fractionCompleted(format style: Foundation.FloatingPointFormatStyle<Double>.Percent = Foundation.FloatingPointFormatStyle<Double>.Percent()
29+
internal static func fractionCompleted(format style: FloatingPointFormatStyle<Double>.Percent = FloatingPointFormatStyle<Double>.Percent()
3130
) -> Option {
3231
return Option(.fractionCompleted(style))
3332
}
@@ -37,33 +36,11 @@ extension ProgressReporter {
3736
/// For example, 5 of 10.
3837
/// - Parameter style: An `IntegerFormatStyle<Int>` instance that should be used to format `completedCount` and `totalCount`.
3938
/// - Returns: A `LocalizedStringResource` for formatted `completedCount` / `totalCount`.
40-
internal static func count(format style: Foundation.IntegerFormatStyle<Int> = Foundation.IntegerFormatStyle<Int>()
39+
internal static func count(format style: IntegerFormatStyle<Int> = IntegerFormatStyle<Int>()
4140
) -> Option {
4241
return Option(.count(style))
4342
}
44-
#else
45-
/// Option specifying`fractionCompleted`.
46-
///
47-
/// For example, 20% completed.
48-
/// - Parameter style: A `FloatingPointFormatStyle<Double>.Percent` instance that should be used to format `fractionCompleted`.
49-
/// - Returns: A `LocalizedStringResource` for formatted `fractionCompleted`.
50-
internal static func fractionCompleted(format style: FoundationInternationalization.FloatingPointFormatStyle<Double>.Percent = FoundationInternationalization.FloatingPointFormatStyle<Double>.Percent()
51-
) -> Option {
52-
return Option(.fractionCompleted(style))
53-
}
54-
55-
/// Option specifying `completedCount` / `totalCount`.
56-
///
57-
/// For example, 5 of 10.
58-
/// - Parameter style: An `IntegerFormatStyle<Int>` instance that should be used to format `completedCount` and `totalCount`.
59-
/// - Returns: A `LocalizedStringResource` for formatted `completedCount` / `totalCount`.
60-
internal static func count(format style: FoundationInternationalization.IntegerFormatStyle<Int> = FoundationInternationalization.IntegerFormatStyle<Int>()
61-
) -> Option {
62-
return Option(.count(style))
63-
}
64-
#endif // FOUNDATION_FRAMEWORK
65-
66-
43+
6744
fileprivate enum RawOption: Codable, Hashable, Equatable {
6845
case count(IntegerFormatStyle<Int>)
6946
case fractionCompleted(FloatingPointFormatStyle<Double>.Percent)
@@ -99,12 +76,20 @@ extension ProgressReporter.FormatStyle: FormatStyle {
9976
let count = reporter.withProperties { p in
10077
return (p.completedCount, p.totalCount)
10178
}
79+
#if FOUNDATION_FRAMEWORK
10280
let countLSR = LocalizedStringResource("\(count.0, format: countStyle) of \(count.1 ?? 0, format: countStyle)", locale: self.locale, bundle: .forClass(ProgressReporter.self))
10381
return String(localized: countLSR)
82+
#else
83+
return "\(count.0.formatted(countStyle.locale(self.locale))) / \((count.1 ?? 0).formatted(countStyle.locale(self.locale)))"
84+
#endif
10485

10586
case .fractionCompleted(let fractionStyle):
87+
#if FOUNDATION_FRAMEWORK
10688
let fractionLSR = LocalizedStringResource("\(reporter.fractionCompleted, format: fractionStyle) completed", locale: self.locale, bundle: .forClass(ProgressReporter.self))
10789
return String(localized: fractionLSR)
90+
#else
91+
return "\(reporter.fractionCompleted.formatted(fractionStyle.locale(self.locale)))"
92+
#endif
10893
}
10994
}
11095
}
@@ -123,7 +108,6 @@ extension ProgressReporter {
123108
}
124109
#endif // FOUNDATION_FRAMEWORK
125110

126-
127111
public func formatted() -> String {
128112
self.formatted(.fractionCompleted())
129113
}
@@ -133,31 +117,15 @@ extension ProgressReporter {
133117
@available(FoundationPreview 6.2, *)
134118
extension FormatStyle where Self == ProgressReporter.FormatStyle {
135119

136-
#if FOUNDATION_FRAMEWORK
137-
public static func fractionCompleted(
138-
format: Foundation.FloatingPointFormatStyle<Double>.Percent = Foundation.FloatingPointFormatStyle<Double>.Percent()
139-
) -> Self {
140-
.init(.fractionCompleted(format: format))
141-
}
142-
143-
public static func count(
144-
format: Foundation.IntegerFormatStyle<Int> = Foundation.IntegerFormatStyle<Int>()
145-
) -> Self {
146-
.init(.count(format: format))
147-
}
148-
#else
149120
public static func fractionCompleted(
150-
format: FoundationInternationalization.FloatingPointFormatStyle<Double>.Percent = FoundationInternationalization.FloatingPointFormatStyle<Double>.Percent()
121+
format: FloatingPointFormatStyle<Double>.Percent = FloatingPointFormatStyle<Double>.Percent()
151122
) -> Self {
152123
.init(.fractionCompleted(format: format))
153124
}
154125

155126
public static func count(
156-
format: FoundationInternationalization.IntegerFormatStyle<Int> = FoundationInternationalization.IntegerFormatStyle<Int>()
127+
format: IntegerFormatStyle<Int> = IntegerFormatStyle<Int>()
157128
) -> Self {
158129
.init(.count(format: format))
159130
}
160-
#endif
161-
162-
163131
}

0 commit comments

Comments
 (0)