Operations with our Integers

In our Playground, we know that numAge is an Int, but with Ints, we also can write arithmetic expressions using numbers, variables/constants, operators, and parentheses. Let's start with addition, subtraction, multiplication, and division. Add the following into Xcode:

// (+) operator
let numSum = 23 + 20
// (-) operator
let numResult = 32 - numSum
// (*) operator
let numTotal = numResult * 5
// (/) operator
let numDivide = numTotal / 10
Operations with our Integers

So, numSum added two integers (+ operator) together, totaling 43 in our preceding example. Then, we subtracted (- operator) numSum from 32 to create numResult (−11 in our example). After ...

Get iOS 10 Programming for Beginners now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.