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

SOLVED: Day 19: Avoiding pickers with the same value

Forums > 100 Days of SwiftUI

I've built a temperature converter app and I was wondering whether there is an easy way to avoid both the input and the output pickers having the same value.

will/didSet won't work with $variables that are binded to the picker.

Should I just ignore this and keep going, hoping to learn it later on the course? Thanks in advance.

2      

Honestly, I wouldn't worry about it.

You could throw up an alert to inform the user that the input and output units are the same, but that seems like overkill; it would really annoy me if I was the user to be interrupted like that to tell me something I can see for myself.

You could change one of the pickers when the same unit is selected in both, but then you have to figure out which unit to change it to. And I guarantee you that you will pick wrong in some situations.

Or you could just let it be and perform the world's easiest unit conversion when input and output are the same. Leave it up to the user to notice "hey, I picked the same units!" and then correct it to whatever they actually need.

2      

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.