6 Compound Assignment Operators in Swift

Опубликовано: 05 Март 2026
на канале: Shiko Matlala
22
0

Like C, Swift provides compound assignment operators that combine assignment (=) with another operation. One example is the addition assignment operator (+=):

var a = 1
a += 2
// a is now equal to 3


The expression a += 2 is shorthand for a = a + 2. Effectively, the addition and the assignment are combined into one operator that performs both tasks at the same time.

https://docs.swift.org/swift-book/Lan...