What is short circuiting?
- Occurs when checking predicate logic.
- E.g: AND operator && -> If the left side of an operator fails, the rest of the predicate will not be checked. No way for the expression to be true.
if emailIsNotEmpty && passwordIsNotEmpty {
...
}
- Also used with an
if let
statement. - If short circuiting did not kick in, the app could crash depending on the latter checks.
if let value = array.first, value != 100 {
...
}
< All Posts