Rules Hub
Coding Rules Library
← Back to all rules
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
mobile ruleP2stack specificStack: swift
swiftguardreadabilitycontrol-flow
Use guard for preconditions and early exit
guard keeps the happy path un-indented and makes the unwrapped value available after the check, unlike nested if let.
PR: mobile-canon-2026-06Created: Jul 5, 2026
Bad example
Old codeswift
| 1 | if let u = user { if u.active { use(u) } } |
Explanation (EN)
Objašnjenje (HR)
Good example
New codeswift
| 1 | guard let u = user, u.active else { return } |
| 2 | use(u) |
Explanation (EN)
Objašnjenje (HR)