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 ruleP1stack specificStack: swift
swifterror-handlingresult
Surface failures with throws or Result, not optional-nil
Returning nil on failure loses the reason; model recoverable failure with throws or Result so callers get the error.
PR: mobile-canon-2026-06Created: Jul 5, 2026
Bad example
Old codeswift
| 1 | func load() -> Data? { try? Data(contentsOf: url) } |
Explanation (EN)
Objašnjenje (HR)
Good example
New codeswift
| 1 | func load() throws -> Data { try Data(contentsOf: url) } |
Explanation (EN)
Objašnjenje (HR)