After just one SwiftUI project we’re being thrown straight into the deep end by being challenged to build our first complete app.
Paul obviously has great faith in us as he challenges us to create a new app from scratch which handles some kind of unit conversion. The requirements are that the user specifies:
- An input unit
- An input amount
- An output unit
And then we calculate and display the correct output value.
My solution

The user interface is going to be very similar to the WeSplit app we just created so I use that as the base for this new app and choose to convert temperature units.
The challenging aspect is how to convert the units. I decide to make a computed property called outputValue
which takes the input amount and uses a switch
statement to convert it to Celsius.
Once I have the input in Celsius I use another switch
statement to convert it to the correct outputUnit
and return it for display.
var outputValue: Double {
var input: Double
// Convert all inputs to Celcius
switch inputUnit {
case "Fahrenheit":
input = ((inputValue - 32) * 5) / 9
case "Kelvin":
input = inputValue - 273.15
default:
input = inputValue
}
// Convert input from Celcius to output unit
switch outputUnit {
case "Fahrenheit":
return ((input * 9) / 5) + 32
case "Kelvin":
return input + 273.15
default:
return input
}
}
Overall, this works great (although you can convert temperatures to below absolute zero which is technically impossible 🥶).
You can find the full solution on GitHub.