-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
String interpolation in SwiftUI Text doesn't work with system locale correctly #169
Comments
I suspect it is because SwiftUI views get the locale from the environment. Does this show the expected value? Text("Z-value: \(model.zValue, format: .measurement(width: .narrow))")
.environment(\.locale, Locale(identifier: "en-CA")) |
Yes it shows the correct unit as "Z-value: 70m". It kind of makes sense that the priority is I set the locale in Simulator as this - locale ID is still "en-US" while the measurement system is changed to Metric. I'll keep digging to see if SwiftUI formatting style APIs support displaying a different measurement system than the locale's default. |
|
On iOS 16 and newer there is var components = Locale.Components(locale: .current)
components.measurementSystem = .metric
let locale = Locale(components: components) |
Thanks Phil. This definitely looks like the correct way to go. Though I tested in iOS 16, it doesn't behave as expected. I'll add this issue to iOS 16 and beyond column and take a look in the future. |
Shows as "Z-value: 70m"
Shows as "Z-value: 230'"
The text was updated successfully, but these errors were encountered: