Skip to content

Commit 8670f76

Browse files
committed
moving files to open source
1 parent 9e26eae commit 8670f76

File tree

9 files changed

+691
-25
lines changed

9 files changed

+691
-25
lines changed

Sources/FoundationEssentials/ProgressReporter/ProgressFraction.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212
#if FOUNDATION_FRAMEWORK
13-
// For feature flag
1413
internal import _ForSwiftFoundation
1514
#endif
1615

@@ -50,10 +49,13 @@ internal struct _ProgressFraction : Sendable, Equatable, CustomDebugStringConver
5049

5150
// ----
5251

52+
#if FOUNDATION_FRAMEWORK
5353
// Glue code for _NSProgressFraction and _ProgressFraction
5454
init(nsProgressFraction: _NSProgressFraction) {
5555
self.init(completed: Int(nsProgressFraction.completed), total: Int(nsProgressFraction.total))
5656
}
57+
#endif
58+
5759

5860
internal mutating func simplify() {
5961
if self.total == 0 {

Sources/FoundationEssentials/ProgressReporter/ProgressReporter+Interop.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,8 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
#if FOUNDATION_FRAMEWORK
14-
// For feature flag
1514
internal import _ForSwiftFoundation
16-
#endif
1715

18-
@_spi(Progress)
1916
@available(FoundationPreview 6.2, *)
2017
//MARK: Progress Parent - ProgressReporter Child Interop
2118
// Actual Progress Parent
@@ -83,7 +80,6 @@ private final class _ProgressParentProgressReporterChild: Sendable {
8380
}
8481
}
8582

86-
@_spi(Progress)
8783
@available(FoundationPreview 6.2, *)
8884
//MARK: ProgressReporter Parent - Progress Child Interop
8985
extension ProgressReporter {
@@ -118,3 +114,4 @@ internal final class _NSProgressParentBridge: Progress, @unchecked Sendable {
118114
actualParent.updateChildFraction(from: _ProgressFraction(nsProgressFraction: fraction.previous), to: _ProgressFraction(nsProgressFraction: fraction.next), portion: Int(portion))
119115
}
120116
}
117+
#endif

Sources/FoundationEssentials/ProgressReporter/ProgressReporter+Progress.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
@_spi(Progress)
1413
@available(FoundationPreview 6.2, *)
1514
// ProgressReporter.Progress
1615
extension ProgressReporter {

Sources/FoundationEssentials/ProgressReporter/ProgressReporter+Properties.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
1010
//
1111
//===----------------------------------------------------------------------===//
12-
@_spi(Progress)
1312
@available(FoundationPreview 6.2, *)
1413
extension ProgressReporter {
1514
// Namespace for properties specific to operations reported on

Sources/FoundationEssentials/ProgressReporter/ProgressReporter.swift

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ internal struct AnyMetatypeWrapper: Hashable, Equatable, Sendable {
3434
}
3535
}
3636

37-
@_spi(Progress)
3837
@available(FoundationPreview 6.2, *)
3938
// ProgressReporter
4039
/// An object that conveys ongoing progress to the user for a specified task.
@@ -54,8 +53,9 @@ internal struct AnyMetatypeWrapper: Hashable, Equatable, Sendable {
5453

5554
// Interop properties - Just kept alive
5655
internal let interopObservation: (any Sendable)? // set at init
56+
#if FOUNDATION_FRAMEWORK
5757
internal let parentBridge: LockedState<Foundation.Progress?> = LockedState(initialState: nil) // dummy, set upon calling setParentBridge
58-
58+
#endif
5959
// Interop properties - Actually set and called
6060
internal let ghostReporter: ProgressReporter? // set at init, used to call notify observers
6161
internal let observers: LockedState<[@Sendable (ObserverState) -> Void]> = LockedState(initialState: [])// storage for all observers, set upon calling addObservers
@@ -430,11 +430,13 @@ internal struct AnyMetatypeWrapper: Hashable, Equatable, Sendable {
430430
}
431431

432432
//MARK: Internal methods to mutate locked context
433+
#if FOUNDATION_FRAMEWORK
433434
internal func setParentBridge(parentBridge: Foundation.Progress) {
434435
self.parentBridge.withLock { bridge in
435436
bridge = parentBridge
436437
}
437438
}
439+
#endif
438440

439441
internal func setInteropChild(interopChild: ProgressReporter) {
440442
state.withLock { state in
@@ -449,7 +451,6 @@ internal struct AnyMetatypeWrapper: Hashable, Equatable, Sendable {
449451
}
450452
}
451453

452-
@_spi(Progress)
453454
@available(FoundationPreview 6.2, *)
454455
// Default Implementation for reduce
455456
extension ProgressReporter.Property where T : AdditiveArithmetic {
@@ -464,7 +465,6 @@ extension ProgressReporter.Property where T : AdditiveArithmetic {
464465
}
465466
}
466467

467-
@_spi(Progress)
468468
@available(FoundationPreview 6.2, *)
469469
// Hashable & Equatable Conformance
470470
extension ProgressReporter: Hashable, Equatable {
@@ -478,7 +478,6 @@ extension ProgressReporter: Hashable, Equatable {
478478
}
479479
}
480480

481-
@_spi(Progress)
482481
@available(FoundationPreview 6.2, *)
483482
extension ProgressReporter: CustomDebugStringConvertible {
484483
/// The description for `completedCount` and `totalCount`.

Sources/FoundationEssentials/ProgressReporter/ProgressReporter+FileFormatStyle.swift renamed to Sources/FoundationInternationalization/ProgressReporter/ProgressReporter+FileFormatStyle.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@
99
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
1010
//
1111
//===----------------------------------------------------------------------===//
12-
@_spi(Progress)
12+
#if canImport(FoundationEssentials)
13+
import FoundationEssentials
14+
#endif
15+
1316
@available(FoundationPreview 6.2, *)
1417
extension ProgressReporter {
1518
//TODO: rdar://149092406 Manual Codable Conformance
@@ -43,7 +46,6 @@ extension ProgressReporter {
4346
}
4447

4548

46-
@_spi(Progress)
4749
@available(FoundationPreview 6.2, *)
4850
extension ProgressReporter.FileFormatStyle: FormatStyle {
4951

@@ -90,7 +92,6 @@ extension ProgressReporter.FileFormatStyle: FormatStyle {
9092
}
9193
}
9294

93-
@_spi(Progress)
9495
@available(FoundationPreview 6.2, *)
9596
// Make access easier to format ProgressReporter
9697
extension ProgressReporter {
@@ -99,7 +100,6 @@ extension ProgressReporter {
99100
}
100101
}
101102

102-
@_spi(Progress)
103103
@available(FoundationPreview 6.2, *)
104104
extension FormatStyle where Self == ProgressReporter.FileFormatStyle {
105105
public static var file: Self {

Sources/FoundationEssentials/ProgressReporter/ProgressReporter+FormatStyle.swift renamed to Sources/FoundationInternationalization/ProgressReporter/ProgressReporter+FormatStyle.swift

Lines changed: 55 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@
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, *)
1617
extension 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, *)
6790
extension 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
92114
extension 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, *)
105134
extension 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

Comments
 (0)