Arithmetic operators - Swift Tutorial

Ozan Emre Duran
AppleCode Chronicles
2 min readJun 5, 2023

In the Swift programming language, arithmetic operators play a fundamental role in performing mathematical calculations on numeric values. Whether you’re adding numbers, subtracting quantities, multiplying factors, dividing values, or finding remainders, Swift provides a set of versatile operators to handle all your arithmetic needs.

Let’s explore the arithmetic operators available in Swift:

Addition (+): The addition operator is used to add two values together.

let sum = 5 + 3 
print(sum) // Output: 8

Subtraction (-): The subtraction operator is used to subtract one value from another.

let difference = 10 - 4 
print(difference) // Output: 6

Multiplication (*): The multiplication operator is used to multiply two values.

let product = 6 * 2 print(product) // Output: 12

Division (/): The division operator is used to divide one value by another.

let quotient = 10 / 2 
print(quotient) // Output: 5

Remainder (%) or Modulo: The remainder operator is used to find the remainder after division.

let remainder = 10 % 3 
print(remainder) // Output: 1
  • Unary Plus (+) and Minus (-): The unary plus operator is used to represent a positive value, and the unary minus operator is used to represent a negative value.
let positiveNumber = +5 
let negativeNumber = -7
print(positiveNumber) // Output: 5
print(negativeNumber) // Output: -7

These are the basic arithmetic operators available in Swift. They can be used with different numeric types such as integers and floating-point numbers to perform calculations in Swift programs.

If you’re interested in learning more about Swift, I recommend checking out my articles on Medium. You can access them through the template I created on Notion, which provides a structured learning process and easy navigation to different topics. Happy learning, and best of luck on your Swift programming journey!

Click here for Notion Swift Tutorial Template :)

--

--

Ozan Emre Duran
AppleCode Chronicles

I'm a passionate programmer who loves exploring and using Apple products. Swift is my language of choice.