Swift Language Precedence of standard Swift operators


Example

Operators that bound tighter (higher precedence) are listed first.

OperatorsPrecedence group (≥3.0)PrecedenceAssociativity
.left
?, !, ++, --, [], (), {}(postfix)
!, ~, +, -, ++, --(prefix)
~> (swift ≤2.3)255left
<<, >>BitwiseShiftPrecedence160none
*, /, %, &, &*MultiplicationPrecedence150left
+, -, |, ^, &+, &-AdditionPrecedence140left
..., ..<RangeFormationPrecedence135none
is, as, as?, as!CastingPrecedence132left
??NilCoalescingPrecedence131right
<, <=, >, >=, ==, !=, ===, !==, ~=ComparisonPrecedence130none
&&LogicalConjunctionPrecedence120left
||LogicalDisjunctionPrecedence110left
DefaultPrecedence*none
?...:TernaryPrecedence100right
=, +=, -=, *=, /=, %=, <<=, >>=, &=, |=, ^=AssignmentPrecedence90right, assignment
->FunctionArrowPrecedenceright
3.0
  • The DefaultPrecedence precedence group is higher than TernaryPrecedence, but is unordered with the rest of the operators. Other than this group, the rest of the precedences are linear.