AIntroduction
The operator is a special symbol or phrase used to check the values or changing the values. The addition operator adds two numbers together. Swift supports most standard c operators and to eliminate common coding errors. Arithmetic operators detect and disallow value overflow and to avoid unexpected results when working with numbers.
Swift allows remainder calculations on floating-point numbers and provide two range operators.
Unary operator
It operates on a single target. Unary prefix operators appear before the target and unary postfix operators appear after the target.
Binary operator
It operates on two targets and infix and appears between two targets.
Ternary operator
It operates on three targets and Swift has only a ternary operator.
Assignment Operator
The assignment operator initialize or update the value and if the right side of the assignment is a tuple with multiple values its elements decomposed into multiple constants. The assignment operator in swift does not return a value.
let b = 10
var a = 5
a = b
Arithmetic operator
Swift has four arithmetic operators like addition, subtraction, multiplication, and division. Swift arithmetic operator does not allow value to overflow by default and it supports the string operation in it.
1 + 2
"hello" + "world"
Remainder Operator
The remainder operator is represented as modulo operator and to determine the solution for a % b the % operator calculates the below equation a= (b * multiplier )+ remainder. the multiplier must be the largest number of multiples of b. The same method is used to calculate the remainder for a negative value.
9 % 4
Increment and Decrement operator
Swift provides an increment operator ++ and a decrement operator to increase or decrease the value of a numeric variable by 1. The operator with variables of any integer or floating-point type is used. The ++ and -- symbol is used as a prefix operator or postfix operator. If the operator is before the variable, it increments the variable before returning its value or if the operator is after the variable, it increments the variable after returning its value.
- var a = 0
- let b = ++a
- // a and b are equal to 1
- let c = a++
- // a has the value 2 but c has set to pre increment value of 1
Unary Minus Operator
The unary minus operator is prepended directly before the value it operates without any white space and the unary plus operator simply return the value it operates on without any change: The unary plus operator does not do anything and it is used to provide symmetry in the code for positive numbers and using unary minus operator for negative numbers.
- let three = 3
- let minusThree = -three
- // minusThree equals -3
- let plusThree = -minusThree
- // plusThree equal 3
- let minusSix = -6
- let alsoMinusSix = +minusSix
- //alsoMinusSix equals -6

Michael RobinsonPosted Nov 27, 2021, 11:14 PM
Thank you for the reference page. However, on this page, you incorrectly state that Swift has increment ++ and decrement -- operators. This has not been true since they were deprecated and removed in Swift v3. Please update your page.