Variables, Constants, and Arrays in Swift

Variables

Variables are a way to give a name to a piece of data, so that it can be referenced in your code later on. Variables are made to vary, so that means they can change as the program progresses.

Syntax:

var myVariable = 9049876543 var typedVariable: String = “Hello Mars” Keyword label = data

Constants

A constant is a way to store data with a name however it will not change throughout the course of a program.

Syntax:

let myConstant = 9048689990 let typedVariable: String = “Hello Mars” Keyword label = data

Arrays

Arrays are a collection of items.

Syntax:

var friends = [John, Darrell, Blake]

Keyword name = [data0, data1, data2]

Data Types

Int 23

Float 1.3

Double 3.141592653589

Bool true/false

String “xyz”

Array [1,2,3]

Dictionary [key: value]