UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

SOLVED: Celsius/Fahrenheit per user location.

Forums > SwiftUI

Is there a way to detect the users locale and set the temperature format (Celsius/Fahrenheit) based on that? I couldn't find a solution that suits my needs.

I want the user to be able to set a temperature for a certain task (say for baking cookies) but I'm missing the right path. The way it works in my head is that the user has to choose their format in the apps setting but I'm not sure if I'm thinking in the right direction.

Thanks for your advice!

1      

Whether a user sees Celsius or Fahrenheit is determined in the Language & Region settings of the device. iOS will use that format automatically when you use the built-in formatting APIs. You don't need to* explicitly set that based on the user's locale.

* And shouldn't. Always respect the user's preferences. What if my locale is the USA but I prefer to see temperatures in Celsius?

2      

Thanks for your quick reply, @roosterboy!

I was thinking in the direction of: @Environment(.colorScheme) as an equivalent to let iOS know we are talking about temperature but I'll dig into the measurement formatter based on your reply. Thanks for pointing me towards that direction!

1      

Hacking with Swift is sponsored by RevenueCat

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

Learn more here

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.