?: operator, formally known as the ternary conditional operator, is a control flow operator that evaluates a boolean expression and returns one of two mutually exclusive expressions based on the result. It is the only ternary operator in Swift, meaning it operates on exactly three operands.
Mechanics and Evaluation Rules
1. Boolean Constraint The first operand must evaluate to a strictBool type. Swift does not support implicit truthiness; passing integers, strings, or optional references directly as the condition results in a compiler error.
- If the condition evaluates to
true, the first expression is evaluated and returned. The second expression is completely ignored. - If the condition evaluates to
false, the second expression is evaluated and returned. The first expression is completely ignored.
Tired of Poor Swift Skills? Fix That With Deep Grasping!Learn More





