|
Hi, I am completely new to the world of programming and have been following Pauls SwiftUI course. I have managed to complete the first challenge and create a temperature unit conversion app. The code isn't very pretty and there are lots of if else in order to convert but it seems to work fine. I have run in to a problem though which I am wondering if there is a solution. Currently the output text box will display the calculation before the input value is entered. For example: If Celcius is selected as input and Kelvin as output, 273.15 is displayed if there is no input value. Is there a way to stop this? Please see the code below.
Any help is much appreciated! |
|
The reason why it shows the calculated output amount is that your eg
PS when |
|
however I would use Use
Convert to lowest common denominator EG Kelvin
|
|
That's awesome Nigel. And thank you for posting a more elegant solution than my messy code! Still so much to learn. Craig |
|
Craig. I was impressed with your logic (as you are only on Day 19) but when you come to use alot of Just a couple of pointers on your code. Look at name of variable etc and try to make them "read" natural (this is hard sometimes) rather then putting Double, ( i know you will see things like When you put comments give details. eg
Keep up the good work and happy coding |
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.
Sponsor Hacking with Swift and reach the world's largest Swift community!
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.
Link copied to your pasteboard.