Skip to content

Commit 4699a1e

Browse files
chrisjrexmbrandonw
andauthored
Add explicit @mainactor to NavigationLink initializer (#3430)
* Add explicit @mainactor to NavigationLink initializer * Access Notification from within an explicit Task Fixes the "Conformance of 'Notification' to 'Sendable' is unavailable" error * Revert "Add explicit @mainactor to NavigationLink initializer" This reverts commit d8cb070. * Add explicit @mainactor to NavigationLink initializer * Update Examples/CaseStudies/SwiftUICaseStudies/03-Effects-LongLiving.swift Co-authored-by: Brandon Williams <[email protected]> * Update swift-navigation dependency version to 2.2.2 * Discard changes to Examples/CaseStudies/CaseStudies.xcodeproj/project.pbxproj * Update ComposableArchitecture.xcworkspace/xcshareddata/swiftpm/Package.resolved * Update ComposableArchitecture.xcworkspace/xcshareddata/swiftpm/Package.resolved * Update ComposableArchitecture.xcworkspace/xcshareddata/swiftpm/Package.resolved * Update ComposableArchitecture.xcworkspace/xcshareddata/swiftpm/Package.resolved * Update ComposableArchitecture.xcworkspace/xcshareddata/swiftpm/Package.resolved * Update ComposableArchitecture.xcworkspace/xcshareddata/swiftpm/Package.resolved * Update Package@swift-6 * Fix tests --------- Co-authored-by: Brandon Williams <[email protected]> Co-authored-by: Brandon Williams <[email protected]>
1 parent 15a2acc commit 4699a1e

File tree

6 files changed

+37
-24
lines changed

6 files changed

+37
-24
lines changed

ComposableArchitecture.xcworkspace/xcshareddata/swiftpm/Package.resolved

Lines changed: 13 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.resolved

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ let package = Package(
2626
.package(url: "https://github.com/pointfreeco/swift-dependencies", from: "1.4.0"),
2727
.package(url: "https://github.com/pointfreeco/swift-identified-collections", from: "1.1.0"),
2828
.package(url: "https://github.com/pointfreeco/swift-macro-testing", from: "0.2.0"),
29-
.package(url: "https://github.com/pointfreeco/swift-navigation", from: "2.1.0"),
29+
.package(url: "https://github.com/pointfreeco/swift-navigation", from: "2.2.2"),
3030
.package(url: "https://github.com/pointfreeco/swift-perception", from: "1.3.4"),
3131
.package(url: "https://github.com/pointfreeco/xctest-dynamic-overlay", from: "1.3.0"),
3232
.package(url: "https://github.com/swiftlang/swift-docc-plugin", from: "1.0.0"),

[email protected]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ let package = Package(
2626
.package(url: "https://github.com/pointfreeco/swift-dependencies", from: "1.4.0"),
2727
.package(url: "https://github.com/pointfreeco/swift-identified-collections", from: "1.1.0"),
2828
.package(url: "https://github.com/pointfreeco/swift-macro-testing", from: "0.2.0"),
29-
.package(url: "https://github.com/pointfreeco/swift-navigation", from: "2.1.0"),
29+
.package(url: "https://github.com/pointfreeco/swift-navigation", from: "2.2.2"),
3030
.package(url: "https://github.com/pointfreeco/swift-perception", from: "1.3.4"),
3131
.package(url: "https://github.com/pointfreeco/xctest-dynamic-overlay", from: "1.3.0"),
3232
.package(url: "https://github.com/swiftlang/swift-docc-plugin", from: "1.0.0"),

Sources/ComposableArchitecture/Observation/NavigationStack+Observation.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,9 @@ extension NavigationLink where Destination == Never {
230230
/// - state: An optional value to present. When the user selects the link, SwiftUI stores a
231231
/// copy of the value. Pass a `nil` value to disable the link.
232232
/// - label: A label that describes the view that this link presents.
233+
#if compiler(>=6)
234+
@MainActor
235+
#endif
233236
public init<P, L: View>(
234237
state: P?,
235238
@ViewBuilder label: () -> L,
@@ -266,6 +269,9 @@ extension NavigationLink where Destination == Never {
266269
/// presents.
267270
/// - state: An optional value to present. When the user selects the link, SwiftUI stores a
268271
/// copy of the value. Pass a `nil` value to disable the link.
272+
#if compiler(>=6)
273+
@MainActor
274+
#endif
269275
public init<P>(
270276
_ titleKey: LocalizedStringKey, state: P?, fileID: StaticString = #fileID, line: UInt = #line
271277
)
@@ -286,6 +292,9 @@ extension NavigationLink where Destination == Never {
286292
/// - title: A string that describes the view that this link presents.
287293
/// - state: An optional value to present. When the user selects the link, SwiftUI stores a
288294
/// copy of the value. Pass a `nil` value to disable the link.
295+
#if compiler(>=6)
296+
@MainActor
297+
#endif
289298
@_disfavoredOverload
290299
public init<S: StringProtocol, P>(
291300
_ title: S, state: P?, fileID: StaticString = #fileID, line: UInt = #line

Tests/ComposableArchitectureTests/EffectCancellationTests.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -388,26 +388,30 @@ final class EffectCancellationTests: BaseTCATestCase {
388388
}
389389
uncheckedUseMainSerialExecutor = false
390390
await Task.yield()
391-
XCTAssertTrue(!Thread.isMainThread)
391+
XCTAssertTrue(!Thread.isMainThread, "Should not be on main thread")
392392
let ids = (1...100).map { _ in UUID() }
393393

394394
let areCancelled = await withTaskGroup(of: Bool.self, returning: [Bool].self) { group in
395395
(1...10_000).forEach { index in
396396
let id = ids[index.quotientAndRemainder(dividingBy: ids.count).remainder]
397397
group.addTask {
398398
await withTaskCancellation(id: id) {
399-
nil == (try? await Task.sleep(nanoseconds: 2_000_000_000))
399+
nil == (try? await Task.sleep(nanoseconds: 10_000_000_000))
400400
}
401401
}
402-
Task {
402+
group.addTask {
403403
try? await Task.sleep(nanoseconds: .random(in: 1_000_000...2_000_000))
404404
Task.cancel(id: id)
405+
return true
405406
}
406407
}
407408
return await group.reduce(into: [Bool]()) { $0.append($1) }
408409
}
409410

410-
XCTAssertTrue(areCancelled.allSatisfy({ isCancelled in isCancelled }))
411+
XCTAssertTrue(
412+
areCancelled.allSatisfy({ isCancelled in isCancelled }),
413+
"All tasks should be cancelled"
414+
)
411415

412416
for id in ids {
413417
XCTAssertEqual(

0 commit comments

Comments
 (0)