I’m trying to integrate Apple’s Translation framework in a Swift 6 project with Approachable Concurrency enabled.
I’m following the code here: https://developer.apple.com/documentation/translation/translating-text-within-your-app#Offer-a-custom-translation
And, specifically, inside the following code
.translationTask(configuration) { session in
do {
// Use the session the task provides to translate the text.
let response = try await session.translate(sourceText)
// Update the view with the translated result.
targetText = response.targetText
} catch {
// Handle any errors.
}
}
On the try await session.translate(…) line, the compiler complains that “Sending ‘session’ risks causing data races”.
Extended error message:
Sending main actor-isolated 'session' to @concurrent instance method 'translate' risks causing data races between @concurrent and main actor-isolated uses
I’ve downloaded Apple’s sample code (at the top of linked webpage), it compiles fine as-is on Xcode 26.4, but fails with the same error as soon as I switch the Swift Language Mode to Swift 6 in the project.
How can I fix this?
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
I've been losing countless hours of work trying to create a variable-width SF Symbol that supports interpolation, no dice. Both Sketch and Figma output SVGs that are not interpolatable.
After numerous hours of research, I believe it's due to the fact that when outlining strokes, these editing tools introduce artifacts into the shapes — sometimes I get very short line segments where there would not be needed, sometimes a 3-point curve gets expanded to a 4-point curve, but not in all weights. It's always inconsistent.
So my only question is rather simple: what's the graphic editing tool Apple uses to create hundreds of symbols? Clearly you cannot edit the stroke of ALL curves by hand, it's inhumane.
Sketch? Figma? Illustrator? Inkscape? Affinity? I'd like a definitive answer from someone internal so that I can at least try to use the same tool as you without wasting more hours.
Hello,
I've been struggling with Measurements when used in SwiftUI.
I want to be able to convert measurements on the fly, but only the first conversion is working. All subsequent ones fail.
I've managed to narrow it down to a reproducible test case.
First, a quick check to see that Foundation works:
// Let’s check that conversion is possible, and works.
var test = Measurement<UnitLength>(value: 13.37, unit: .meters)
print("Original value: \(test.formatted(.measurement(width: .abbreviated, usage: .asProvided, numberFormatStyle: .number)))")
// prints: Original value: 13.37 m
test.convert(to: .centimeters)
print("In centimeters: \(test.formatted(.measurement(width: .abbreviated, usage: .asProvided, numberFormatStyle: .number)))")
// prints: In centimeters: 1,337 cm
test.convert(to: .kilometers)
print("In kilometers: \(test.formatted(.measurement(width: .abbreviated, usage: .asProvided, numberFormatStyle: .number)))")
// prints: In kilometers: 0.01337 km
test.convert(to: .meters)
print("Back to meters: \(test.formatted(.measurement(width: .abbreviated, usage: .asProvided, numberFormatStyle: .number)))")
// prints: Back to meters: 13.37 m
Okay, so it works on the Foundation level. I can convert measurements back and forth, many times.
Now run this ContentView below, and click/tap any button.
First time will succeed, further times will fail.
struct ContentView: View {
@State var distance = Measurement<UnitLength>(value: 13.37, unit: .meters)
var body: some View {
VStack {
Text("Distance = \(distance.formatted(.measurement(width: .abbreviated, usage: .asProvided, numberFormatStyle: .number)))")
Button("Convert to cm") { print("Convert to cm"); distance.convert(to: .centimeters) }
Button("Convert to m") { print("Convert to m"); distance.convert(to: .meters) }
Button("Convert to km") { print("Convert to km"); distance.convert(to: .kilometers) }
}
.onChange(of: distance, perform: { _ in
print("→ new distance = \(distance.formatted(.measurement(width: .abbreviated, usage: .asProvided, numberFormatStyle: .number)))")
})
.frame(minWidth: 300)
.padding()
}
}
Replacing distance.convert() with distance = distance.converted() does not help.
This is reproducible both on macOS and iOS.
Why on Earth does the first conversion succeed, then all subsequent ones fail? The onChange isn't even triggered.
// Edit: I'm on Xcode 13.3, macOS 12.3, iOS 15.4