Swiftly

Swift 5.1 references for busy coders

Assignment (=, +=. -=, *=, /=)

Assignment operator (=)

var a = 10
var b = a
print("\(a), \(b)") // 10, 10
b = 15
print("\(a), \(b)") // 10, 15

Compound assignment operators

Addition (+=)

var a = 10
a += 5
print(a) // 15

Subtraction (-=)

var a = 10
a -= 5
print(a) // 5

Multiplication (*=)

var a = 10
a *= 5
print(a) // 50

Division (/=)

var a = 10
a /= 5
print(a) // 2