Skip to content

Commit 9ba6c07

Browse files
committed
add if FOUNDATION_FRAMEWORK in relevant areas
1 parent ba43752 commit 9ba6c07

File tree

3 files changed

+69
-5
lines changed

3 files changed

+69
-5
lines changed

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

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ extension ProgressManager {
132132
return try state.withLock { (state) throws(E) -> T in
133133
var values = Values(state: state)
134134
// This is done to avoid copy on write later
135+
#if FOUNDATION_FRAMEWORK
135136
state = State(
136137
selfFraction: ProgressFraction(),
137138
children: [],
@@ -148,6 +149,22 @@ extension ProgressManager {
148149
interopObservation: InteropObservation(subprogressBridge: nil),
149150
observers: []
150151
)
152+
#else
153+
state = State(
154+
selfFraction: ProgressFraction(),
155+
children: [],
156+
parents: [],
157+
totalFileCount: ProgressManager.Properties.TotalFileCount.defaultValue,
158+
completedFileCount: ProgressManager.Properties.CompletedFileCount.defaultValue,
159+
totalByteCount: ProgressManager.Properties.TotalByteCount.defaultValue,
160+
completedByteCount: ProgressManager.Properties.CompletedByteCount.defaultValue,
161+
throughput: ProgressManager.Properties.Throughput.defaultValue,
162+
estimatedTimeRemaining: ProgressManager.Properties.EstimatedTimeRemaining.defaultValue,
163+
propertiesInt: [:],
164+
propertiesDouble: [:],
165+
propertiesString: [:]
166+
)
167+
#endif
151168
let result = try closure(&values)
152169
if values.fractionalCountDirty {
153170
markSelfDirty(parents: values.state.parents)
@@ -198,12 +215,13 @@ extension ProgressManager {
198215
markSelfDirty(property: property, parents: values.state.parents)
199216
}
200217
}
201-
218+
#if FOUNDATION_FRAMEWORK
202219
if let observerState = values.observerState {
203220
if let _ = state.interopObservation.reporterBridge {
204221
notifyObservers(with: observerState)
205222
}
206223
}
224+
#endif
207225
state = values.state
208226
return result
209227
}
@@ -226,7 +244,9 @@ extension ProgressManager {
226244
internal var dirtyPropertiesInt: [MetatypeWrapper<Int>] = []
227245
internal var dirtyPropertiesDouble: [MetatypeWrapper<Double>] = []
228246
internal var dirtyPropertiesString: [MetatypeWrapper<String>] = []
247+
#if FOUNDATION_FRAMEWORK
229248
internal var observerState: ObserverState?
249+
#endif
230250

231251
/// The total units of work.
232252
public var totalCount: Int? {
@@ -241,7 +261,9 @@ extension ProgressManager {
241261

242262
state.selfFraction.total = newValue
243263

264+
#if FOUNDATION_FRAMEWORK
244265
interopNotifications()
266+
#endif
245267

246268
fractionalCountDirty = true
247269
}
@@ -260,8 +282,9 @@ extension ProgressManager {
260282

261283
state.selfFraction.completed = newValue
262284

285+
#if FOUNDATION_FRAMEWORK
263286
interopNotifications()
264-
287+
#endif
265288
fractionalCountDirty = true
266289
}
267290
}
@@ -462,11 +485,12 @@ extension ProgressManager {
462485
dirtyPropertiesString.append(MetatypeWrapper(P.self))
463486
}
464487
}
465-
488+
#if FOUNDATION_FRAMEWORK
466489
private mutating func interopNotifications() {
467490
state.interopObservation.subprogressBridge?.manager.notifyObservers(with:.fractionUpdated(totalCount: state.selfFraction.total ?? 0, completedCount: state.selfFraction.completed))
468491

469492
self.observerState = .fractionUpdated(totalCount: state.selfFraction.total ?? 0, completedCount: state.selfFraction.completed)
470493
}
494+
#endif
471495
}
472496
}

Sources/FoundationEssentials/ProgressManager/ProgressManager.swift

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ internal import _FoundationCollections
9595
return .init(manager: self)
9696
}
9797

98+
#if FOUNDATION_FRAMEWORK
9899
internal init(total: Int?, completed: Int?, subprogressBridge: SubprogressBridge?) {
99100
let state = State(
100101
selfFraction: ProgressFraction(completed: completed ?? 0, total: total),
@@ -116,6 +117,26 @@ internal import _FoundationCollections
116117
)
117118
self.state = Mutex(state)
118119
}
120+
#else
121+
internal init(total: Int?, completed: Int?) {
122+
let state = State(
123+
selfFraction: ProgressFraction(completed: completed ?? 0, total: total),
124+
children: [],
125+
parents: [],
126+
totalFileCount: ProgressManager.Properties.TotalFileCount.defaultValue,
127+
completedFileCount: ProgressManager.Properties.CompletedFileCount.defaultValue,
128+
totalByteCount: ProgressManager.Properties.TotalByteCount.defaultValue,
129+
completedByteCount: ProgressManager.Properties.CompletedByteCount.defaultValue,
130+
throughput: ProgressManager.Properties.Throughput.defaultValue,
131+
estimatedTimeRemaining: ProgressManager.Properties.EstimatedTimeRemaining.defaultValue,
132+
fileURL: ProgressManager.Properties.FileURL.defaultValue,
133+
propertiesInt: [:],
134+
propertiesDouble: [:],
135+
propertiesString: [:]
136+
)
137+
self.state = Mutex(state)
138+
}
139+
#endif
119140

120141
/// Initializes `self` with `totalCount`.
121142
///
@@ -164,7 +185,8 @@ internal import _FoundationCollections
164185
}
165186

166187
state.selfFraction.completed += count
167-
188+
189+
#if FOUNDATION_FRAMEWORK
168190
state.interopObservation.subprogressBridge?.manager.notifyObservers(
169191
with: .fractionUpdated(
170192
totalCount: state.selfFraction.total ?? 0,
@@ -180,6 +202,7 @@ internal import _FoundationCollections
180202
)
181203
)
182204
}
205+
#endif
183206

184207
return state.parents
185208
}

Sources/FoundationEssentials/ProgressManager/Subprogress.swift

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,32 @@ public struct Subprogress: ~Copyable, Sendable {
1919
internal var parent: ProgressManager
2020
internal var portionOfParent: Int
2121
internal var isInitializedToProgressReporter: Bool
22+
#if FOUNDATION_FRAMEWORK
2223
internal var subprogressBridge: SubprogressBridge?
23-
24+
#endif
25+
26+
#if FOUNDATION_FRAMEWORK
2427
internal init(parent: ProgressManager, portionOfParent: Int, subprogressBridge: SubprogressBridge? = nil) {
2528
self.parent = parent
2629
self.portionOfParent = portionOfParent
2730
self.isInitializedToProgressReporter = false
2831
self.subprogressBridge = subprogressBridge
2932
}
33+
#else
34+
internal init(parent: ProgressManager, portionOfParent: Int) {
35+
self.parent = parent
36+
self.portionOfParent = portionOfParent
37+
self.isInitializedToProgressReporter = false
38+
}
39+
#endif
3040

3141
/// Instantiates a ProgressManager which is a child to the parent from which `self` is returned.
3242
/// - Parameter totalCount: Total count of returned child `ProgressManager` instance.
3343
/// - Returns: A `ProgressManager` instance.
3444
public consuming func start(totalCount: Int?) -> ProgressManager {
3545
isInitializedToProgressReporter = true
3646

47+
#if FOUNDATION_FRAMEWORK
3748
let childManager = ProgressManager(
3849
total: totalCount,
3950
completed: nil,
@@ -44,6 +55,12 @@ public struct Subprogress: ~Copyable, Sendable {
4455
subprogressBridge?.manager.setInteropChild(interopChild: childManager)
4556
return childManager
4657
}
58+
#else
59+
let childManager = ProgressManager(
60+
total: totalCount,
61+
completed: nil
62+
)
63+
#endif
4764

4865
let position = parent.addChild(
4966
child: childManager,

0 commit comments

Comments
 (0)