Swift - Operator Operators

Introduction

To work with the contents of variables, you use operators.

There are a wide variety of operators built into Swift.

The most common of which are the arithmetic operators, such as addition or division:

1 + 7 // 8 
6 - 4 // 2 
8 / 2 // 4 
3 * 5 // 15 

You can use equality operators. These check to see if two values are the same:

2 == 2        // true 
2  != 2        // false 
"yes" == "no" // false 
"yes"  != "no" // true 

The comparison operators. These compare how similar two variables are to one another:

5 < 7  // true 
1 > 4  // false 
2 <= 1 // false 
3 >= 3 // true 

The . operator lets you access properties and methods of your variables:

true.description  // "true" 
4.advanced(by: 3) // 7