I added a dummy view - copy paste directly from the Apple Developer Documentation, in a swift package using swift 6 and got concurency error. The fix is to switch to swift 5
It’s hard to investigate Swift concurrency problems without knowing more about your build environment, so I tried reproducing this here in my office:
- Using Xcode 26.5, I created a new project from the iOS > App template.
- I changed it to use the Swift 6 language mode.
- I changed
ContentView.swiftto this:
import SwiftUI
/* @preconcurrency */ import DeclaredAgeRange
struct ContentView: View {
@Environment(\.requestAgeRange) var requestAgeRange
var body: some View {
VStack {
Button("Test") {
Task {
do {
let response = try await requestAgeRange(ageGates: 13, 15, 18)
// ^
// Sending value of non-Sendable type 'DeclaredAgeRangeAction' risks
// causing data races
//
// Sending main actor-isolated value of non-Sendable type
// 'DeclaredAgeRangeAction' to @concurrent instance method
// 'callAsFunction(ageGates:_:_:)' risks causing races in between
// main actor-isolated and @concurrent uses
print(response)
} catch {
}
}
}
}
.padding()
}
}
#Preview {
ContentView()
}
I think this accurately reflects the error you’re seeing, but lemme know otherwise.
As to the root cause of this error:
requestAgeRange, of typeDeclaredAgeRangeAction, is bound to the main actor because it’s part of the view.- You’re calling it as a function, using the machinery introduced in SE-0253 Callable values of user-defined nominal types.
- That effectively passes the
selfvalue to that function. - But the function is not declared to be main actor isolated, so now you’re passing a value between two isolation domains.
IMO this is a bug in the declaration of DeclaredAgeRangeAction. I’m not sure what the right fix is, but from your perspective the path forward is clear:
- Suppress the error temporarily by using
@preconcurrencyto import the Declared Age Range framework. - File a bug against
DeclaredAgeRangeActionrequesting a proper fix for this.
Please post your bug number, just for the record.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"