Skip to content

Commit

Permalink
Add explicit @mainactor to NavigationLink initializer (#3430)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
3 people authored Oct 9, 2024
1 parent 15a2acc commit 4699a1e
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"originHash" : "876e72a5524942f6ac9fd0ebc53b055352a228c6f751c04f66249c1eeefd2cbc",
"originHash" : "345ca5e011bfdb9a07d4b2a72a36fac771eb8263e2cd8901042f6e807a599841",
"pins" : [
{
"identity" : "combine-schedulers",
Expand All @@ -15,8 +15,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-case-paths",
"state" : {
"revision" : "642e6aab8e03e5f992d9c83e38c5be98cfad5078",
"version" : "1.5.5"
"revision" : "bc92c4b27f9a84bfb498cdbfdf35d5a357e9161f",
"version" : "1.5.6"
}
},
{
Expand All @@ -33,8 +33,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-collections",
"state" : {
"revision" : "9bf03ff58ce34478e66aaee630e491823326fd06",
"version" : "1.1.3"
"revision" : "671108c96644956dddcd89dd59c203dcdb36cec7",
"version" : "1.1.4"
}
},
{
Expand All @@ -60,8 +60,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-dependencies",
"state" : {
"revision" : "fd1fb25b68fdb9756cd61d23dbd9e2614b340085",
"version" : "1.4.0"
"revision" : "0fc0255e780bf742abeef29dec80924f5f0ae7b9",
"version" : "1.4.1"
}
},
{
Expand Down Expand Up @@ -105,8 +105,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-navigation",
"state" : {
"revision" : "e834b3760731160d7d448509ee6a1408c8582a6b",
"version" : "2.2.0"
"revision" : "16a27ab7ae0abfefbbcba73581b3e2380b47a579",
"version" : "2.2.2"
}
},
{
Expand All @@ -132,8 +132,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/swiftlang/swift-syntax",
"state" : {
"revision" : "515f79b522918f83483068d99c68daeb5116342d",
"version" : "600.0.0-prerelease-2024-09-04"
"revision" : "0687f71944021d616d34d922343dcef086855920",
"version" : "600.0.1"
}
},
{
Expand All @@ -150,8 +150,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/xctest-dynamic-overlay",
"state" : {
"revision" : "bc2a151366f2cd0e347274544933bc2acb00c9fe",
"version" : "1.4.0"
"revision" : "770f990d3e4eececb57ac04a6076e22f8c97daeb",
"version" : "1.4.2"
}
}
],
Expand Down
10 changes: 5 additions & 5 deletions Package.resolved
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"originHash" : "56d9c3bb35bdc40e748375720c367811b810b36e68baa234d35a7e72bad5ff39",
"originHash" : "e2618e836df1ca46810fbd99802b7402f1b1f9397b7b0d4d9f5ed2a60edd0a1f",
"pins" : [
{
"identity" : "combine-schedulers",
Expand Down Expand Up @@ -42,8 +42,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-concurrency-extras",
"state" : {
"revision" : "bb5059bde9022d69ac516803f4f227d8ac967f71",
"version" : "1.1.0"
"revision" : "6054df64b55186f08b6d0fd87152081b8ad8d613",
"version" : "1.2.0"
}
},
{
Expand Down Expand Up @@ -105,8 +105,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-navigation",
"state" : {
"revision" : "e834b3760731160d7d448509ee6a1408c8582a6b",
"version" : "2.2.0"
"revision" : "16a27ab7ae0abfefbbcba73581b3e2380b47a579",
"version" : "2.2.2"
}
},
{
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ let package = Package(
.package(url: "https://github.com/pointfreeco/swift-dependencies", from: "1.4.0"),
.package(url: "https://github.com/pointfreeco/swift-identified-collections", from: "1.1.0"),
.package(url: "https://github.com/pointfreeco/swift-macro-testing", from: "0.2.0"),
.package(url: "https://github.com/pointfreeco/swift-navigation", from: "2.1.0"),
.package(url: "https://github.com/pointfreeco/swift-navigation", from: "2.2.2"),
.package(url: "https://github.com/pointfreeco/swift-perception", from: "1.3.4"),
.package(url: "https://github.com/pointfreeco/xctest-dynamic-overlay", from: "1.3.0"),
.package(url: "https://github.com/swiftlang/swift-docc-plugin", from: "1.0.0"),
Expand Down
2 changes: 1 addition & 1 deletion [email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ let package = Package(
.package(url: "https://github.com/pointfreeco/swift-dependencies", from: "1.4.0"),
.package(url: "https://github.com/pointfreeco/swift-identified-collections", from: "1.1.0"),
.package(url: "https://github.com/pointfreeco/swift-macro-testing", from: "0.2.0"),
.package(url: "https://github.com/pointfreeco/swift-navigation", from: "2.1.0"),
.package(url: "https://github.com/pointfreeco/swift-navigation", from: "2.2.2"),
.package(url: "https://github.com/pointfreeco/swift-perception", from: "1.3.4"),
.package(url: "https://github.com/pointfreeco/xctest-dynamic-overlay", from: "1.3.0"),
.package(url: "https://github.com/swiftlang/swift-docc-plugin", from: "1.0.0"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,9 @@ extension NavigationLink where Destination == Never {
/// - state: An optional value to present. When the user selects the link, SwiftUI stores a
/// copy of the value. Pass a `nil` value to disable the link.
/// - label: A label that describes the view that this link presents.
#if compiler(>=6)
@MainActor
#endif
public init<P, L: View>(
state: P?,
@ViewBuilder label: () -> L,
Expand Down Expand Up @@ -266,6 +269,9 @@ extension NavigationLink where Destination == Never {
/// presents.
/// - state: An optional value to present. When the user selects the link, SwiftUI stores a
/// copy of the value. Pass a `nil` value to disable the link.
#if compiler(>=6)
@MainActor
#endif
public init<P>(
_ titleKey: LocalizedStringKey, state: P?, fileID: StaticString = #fileID, line: UInt = #line
)
Expand All @@ -286,6 +292,9 @@ extension NavigationLink where Destination == Never {
/// - title: A string that describes the view that this link presents.
/// - state: An optional value to present. When the user selects the link, SwiftUI stores a
/// copy of the value. Pass a `nil` value to disable the link.
#if compiler(>=6)
@MainActor
#endif
@_disfavoredOverload
public init<S: StringProtocol, P>(
_ title: S, state: P?, fileID: StaticString = #fileID, line: UInt = #line
Expand Down
12 changes: 8 additions & 4 deletions Tests/ComposableArchitectureTests/EffectCancellationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -388,26 +388,30 @@ final class EffectCancellationTests: BaseTCATestCase {
}
uncheckedUseMainSerialExecutor = false
await Task.yield()
XCTAssertTrue(!Thread.isMainThread)
XCTAssertTrue(!Thread.isMainThread, "Should not be on main thread")
let ids = (1...100).map { _ in UUID() }

let areCancelled = await withTaskGroup(of: Bool.self, returning: [Bool].self) { group in
(1...10_000).forEach { index in
let id = ids[index.quotientAndRemainder(dividingBy: ids.count).remainder]
group.addTask {
await withTaskCancellation(id: id) {
nil == (try? await Task.sleep(nanoseconds: 2_000_000_000))
nil == (try? await Task.sleep(nanoseconds: 10_000_000_000))
}
}
Task {
group.addTask {
try? await Task.sleep(nanoseconds: .random(in: 1_000_000...2_000_000))
Task.cancel(id: id)
return true
}
}
return await group.reduce(into: [Bool]()) { $0.append($1) }
}

XCTAssertTrue(areCancelled.allSatisfy({ isCancelled in isCancelled }))
XCTAssertTrue(
areCancelled.allSatisfy({ isCancelled in isCancelled }),
"All tasks should be cancelled"
)

for id in ids {
XCTAssertEqual(
Expand Down

0 comments on commit 4699a1e

Please sign in to comment.