Precedence of standard Swift operators
suggest changeOperators that bind tighter (higher precedence) are listed first. ++ and -- were removed in Swift 3. The numeric precedence column is the older Swift 2 ordering.
| Operators | Precedence group (≥3.0) | Precedence | Associativity |
|---|---|---|---|
. |
∞ | left | |
?, !, ++, --, [], (), {} |
(postfix) | ||
!, ~, +, -, ++, -- |
(prefix) | ||
~> (Swift ≤2.3) |
255 | left | |
<<, >> |
BitwiseShiftPrecedence | 160 | none |
*, /, %, &, &* |
MultiplicationPrecedence | 150 | left |
+, -, |, ^, &+, &- |
AdditionPrecedence | 140 | left |
..., ..< |
RangeFormationPrecedence | 135 | none |
is, as, as?, as! |
CastingPrecedence | 132 | left |
?? |
NilCoalescingPrecedence | 131 | right |
<, <=, >, >=, ==, !=, ===, !==, ~= |
ComparisonPrecedence | 130 | none |
&& |
LogicalConjunctionPrecedence | 120 | left |
|| |
LogicalDisjunctionPrecedence | 110 | left |
| DefaultPrecedence | none | ||
?…: |
TernaryPrecedence | 100 | right |
=, +=, -=, *=, /=, %=, <<=, >>=, &=, |=, ^= |
AssignmentPrecedence | 90 | right, assignment |
-> |
FunctionArrowPrecedence | right |
- The
DefaultPrecedencegroup is higher thanTernaryPrecedence, but it is unordered relative to the other groups. Aside from that group, these precedences are linear. - This table can also be found in Apple’s API reference.
- The precedence groups are defined in the standard library source.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents