Hey again, let’s dive deeper into Swift. Power up your Xcode playground and let’s get going!
Creating a Variable
var myVariable = "Hello"
var myVariable = 3
You can also create a string (or any other type for that matter), my explicitly declaring it a string. Let’s check that out.
var myVariable: String = "Hello"
That’s the same as the first line of code. As such, you can also define a double in the same manner.
var myVariable: Double = 5.0
Easy? It’s quite simple!
Creating a Constant
Use the let keyword to define a constant. Let;s take a look at an example.
let myVariable = 2
Bam, there’s a constant. See the below code for defining a BOOL.
var myVariable = true