The first couple of days are a gentle introduction to some basic programming concepts. We’re starting off by learning some Swift, rather than SwiftUI.
Swift is a general purpose programming language used for program flow, logic, calculations etc whereas SwiftUI is used for laying out interfaces. It’s crucial to know both to make useful apps but it makes sense to start with Swift.
Day 1 covers the difference between variables (var
) and constants (let
), then moves on to some data types like string
, int
and double
. We also cover how to print text out to the console.
Day 2 covers the boolean
data type then moves on to string interpolation, which is just embedding variable and constant values into strings of text.
Checkpoint 1
At the end of Day 2 comes our first Checkpoint. The task is to:
- Create a constant containing a value in Celcius.
- Convert it to Fahrenheit using the appropriate formula.
- Print out the result as a sentence showing both values.
This is a nice easy starter, my solution is below.
import Cocoa
// Convert a given celcius temperature to fahrenheit
let celcius = 20.0
let fahrenheit = ((celcius * 9) / 5) + 32
print("\(celcius)°C is \(fahrenheit)°F")