99// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
1010//
1111//===----------------------------------------------------------------------===//
12-
12+ #if canImport(FoundationEssentials)
13+ import FoundationEssentials
14+ #endif
1315// Outlines the options available to format ProgressReporter
14- @_spi ( Progress)
1516@available ( FoundationPreview 6 . 2 , * )
1617extension ProgressReporter {
1718
@@ -20,12 +21,33 @@ extension ProgressReporter {
2021 // Outlines the options available to format ProgressReporter
2122 internal struct Option : Sendable , Codable , Hashable , Equatable {
2223
24+ #if FOUNDATION_FRAMEWORK
25+ /// Option specifying`fractionCompleted`.
26+ ///
27+ /// For example, 20% completed.
28+ /// - Parameter style: A `FloatingPointFormatStyle<Double>.Percent` instance that should be used to format `fractionCompleted`.
29+ /// - Returns: A `LocalizedStringResource` for formatted `fractionCompleted`.
30+ internal static func fractionCompleted( format style: Foundation . FloatingPointFormatStyle < Double > . Percent = Foundation . FloatingPointFormatStyle< Double> . Percent( )
31+ ) -> Option {
32+ return Option ( . fractionCompleted( style) )
33+ }
34+
35+ /// Option specifying `completedCount` / `totalCount`.
36+ ///
37+ /// For example, 5 of 10.
38+ /// - Parameter style: An `IntegerFormatStyle<Int>` instance that should be used to format `completedCount` and `totalCount`.
39+ /// - Returns: A `LocalizedStringResource` for formatted `completedCount` / `totalCount`.
40+ internal static func count( format style: Foundation . IntegerFormatStyle < Int > = Foundation . IntegerFormatStyle < Int > ( )
41+ ) -> Option {
42+ return Option ( . count( style) )
43+ }
44+ #else
2345 /// Option specifying`fractionCompleted`.
2446 ///
2547 /// For example, 20% completed.
2648 /// - Parameter style: A `FloatingPointFormatStyle<Double>.Percent` instance that should be used to format `fractionCompleted`.
2749 /// - Returns: A `LocalizedStringResource` for formatted `fractionCompleted`.
28- internal static func fractionCompleted( format style: FloatingPointFormatStyle < Double > . Percent = FloatingPointFormatStyle< Double> . Percent( )
50+ internal static func fractionCompleted( format style: FoundationInternationalization . FloatingPointFormatStyle < Double > . Percent = FoundationInternationalization . FloatingPointFormatStyle< Double> . Percent( )
2951 ) -> Option {
3052 return Option ( . fractionCompleted( style) )
3153 }
@@ -35,10 +57,12 @@ extension ProgressReporter {
3557 /// For example, 5 of 10.
3658 /// - Parameter style: An `IntegerFormatStyle<Int>` instance that should be used to format `completedCount` and `totalCount`.
3759 /// - Returns: A `LocalizedStringResource` for formatted `completedCount` / `totalCount`.
38- internal static func count( format style: IntegerFormatStyle < Int > = IntegerFormatStyle < Int > ( )
60+ internal static func count( format style: FoundationInternationalization . IntegerFormatStyle < Int > = FoundationInternationalization . IntegerFormatStyle < Int > ( )
3961 ) -> Option {
4062 return Option ( . count( style) )
4163 }
64+ #endif // FOUNDATION_FRAMEWORK
65+
4266
4367 fileprivate enum RawOption : Codable , Hashable , Equatable {
4468 case count( IntegerFormatStyle < Int > )
@@ -62,7 +86,6 @@ extension ProgressReporter {
6286 }
6387}
6488
65- @_spi ( Progress)
6689@available ( FoundationPreview 6 . 2 , * )
6790extension ProgressReporter . FormatStyle : FormatStyle {
6891
@@ -86,32 +109,55 @@ extension ProgressReporter.FormatStyle: FormatStyle {
86109 }
87110}
88111
89- @_spi ( Progress)
90112@available ( FoundationPreview 6 . 2 , * )
91113// Make access easier to format ProgressReporter
92114extension ProgressReporter {
115+
116+ #if FOUNDATION_FRAMEWORK
93117 public func formatted< F: Foundation . FormatStyle > ( _ style: F ) -> F . FormatOutput where F. FormatInput == ProgressReporter {
94118 style. format ( self )
95119 }
120+ #else
121+ public func formatted< F: FoundationEssentials . FormatStyle > ( _ style: F ) -> F . FormatOutput where F. FormatInput == ProgressReporter {
122+ style. format ( self )
123+ }
124+ #endif // FOUNDATION_FRAMEWORK
96125
126+
97127 public func formatted( ) -> String {
98128 self . formatted ( . fractionCompleted( ) )
99129 }
100130
101131}
102132
103- @_spi ( Progress)
104133@available ( FoundationPreview 6 . 2 , * )
105134extension FormatStyle where Self == ProgressReporter . FormatStyle {
135+
136+ #if FOUNDATION_FRAMEWORK
106137 public static func fractionCompleted(
107- format: FloatingPointFormatStyle < Double > . Percent = FloatingPointFormatStyle< Double> . Percent( )
138+ format: Foundation . FloatingPointFormatStyle < Double > . Percent = Foundation . FloatingPointFormatStyle< Double> . Percent( )
108139 ) -> Self {
109140 . init( . fractionCompleted( format: format) )
110141 }
111142
112143 public static func count(
113- format: IntegerFormatStyle < Int > = IntegerFormatStyle < Int > ( )
144+ format: Foundation . IntegerFormatStyle < Int > = Foundation . IntegerFormatStyle < Int > ( )
114145 ) -> Self {
115146 . init( . count( format: format) )
116147 }
148+ #else
149+ public static func fractionCompleted(
150+ format: FoundationInternationalization . FloatingPointFormatStyle < Double > . Percent = FoundationInternationalization . FloatingPointFormatStyle< Double> . Percent( )
151+ ) -> Self {
152+ . init( . fractionCompleted( format: format) )
153+ }
154+
155+ public static func count(
156+ format: FoundationInternationalization . IntegerFormatStyle < Int > = FoundationInternationalization . IntegerFormatStyle < Int > ( )
157+ ) -> Self {
158+ . init( . count( format: format) )
159+ }
160+ #endif
161+
162+
117163}
0 commit comments