Swift - Operator Assignment Operator

Introduction

The assignment operator = sets a variable or constant to a value.

In Swift, you can create a constant by assigning a value to a constant name as shown here:

let companyName = "abc"
let factor = 5

You can create a variable using the assignment operator:

var customerName1 = "abc"

You can assign a variable or constant to another:

var customerName2 = customerName1

You can assign a tuple directly to a variable or constant:

let pt1 =  (3,4)

You can decompose the value of a tuple into multiple variables or constants by using the assignment operator:

Demo

let (x,y) = (5,6)
print(x)   //5
print(y)   //6

Result

Related Topics