| Start |
|---|
| Booleans and Inline Conditionals A clean way to handle booleans is using an inline conditional with the a ? b : c ternary operator, which is part of Swift's Basic Operations (opens new window). The inline conditional is made up of 3 components: where question is a boolean that is evaluated and answerIfTrue is the value returned if the question is true, and answerIfFalse is the value returned if the question is false. The expression above is the same as: With inline conditionals you return a value based on a boolean: You can also call methods based on a boolean value: Inline conditionals allow for clean one-liner boolean evaluations |
| What is Bool? Bool (opens new window) is a Boolean (opens new window) type with two possible values: Bools are used in control-flow statements as conditions.
The |
| Negate a Bool with the prefix ! operator The prefix |
| Boolean Logical Operators The OR (||) operator returns true if one of its two operands evaluates to true, otherwise it returns false. For example, the following code evaluates to true because at least one of the expressions either side of the OR operator is true: The AND (&&) operator returns true only if both operands evaluate to be true. The following example will return false because only one of the two operand expressions evaluates to true: The XOR (^) operator returns true if one and only one of the two operands evaluates to true. For example, the following code will return true since only one operator evaluates to be true: |
Read Article
https://develop.horje.com/learn/1434/reference