Variables in Swift are used to store information that can be used and changed throughout your code. You define a variable using the var
keyword followed by a name and a type. For example:
var greeting: String = "Hello, World!"
In this example, greeting
is a variable of type String
, and it's initially set to "Hello, World!". You can change its value later in the code.