Swift Operators


Swift Operators

Operators are symbols used to perform actions on values or variables. Swift includes many types of operators:


1. Arithmetic Operators

Do basic math:

+  -  *  /  %

Example:

let total = 5 + 3  // total is 8

2. Assignment Operator

Used to give a value to a variable:

=

Example:

var name = "Swift"

3. Comparison Operators

Compare two values:

==   =  >  <  >=  <=

Example:

5 > 2  // true

4. Logical Operators

Combine or invert conditions:

&&  ||  !

Example:

true && false  // false

5. Unary Operators

Work with a single value:

!  -  +

Example:

let isFalse = !true  // false

6. Ternary Operator

A quick way to write if-else in one line:

condition ? trueResult : falseResult

Example:

let result = age >= 18 ? "Adult" : "Minor"

Summary

Operators help you calculate, compare, and make decisions in your code with just a few symbols. Swift makes them easy and readable.


Prefer Learning by Watching?

Watch these YouTube tutorials to understand GIT Tutorial visually:

What You'll Learn:
  • 📌 How to write if-statements and use operators | Swift Basics #4
  • 📌 Learn to Code Swift - What Are Logical Operators?
Previous Next