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
swiftmodelextensiondry
Put derived model values in computed properties/extensions
Compute display/derived values (formatted price, vintage, full name) in a computed property or model extension instead of unwrapping inline at each call site.
PR: mobile-mining-2026-06Created: Jul 5, 2026
Bad example
Old codeswift
| 1 | if let v = wine.vintage { label.text = String(v) } else { label.text = "-" } |
Explanation (EN)
Objašnjenje (HR)
Good example
New codeswift
| 1 | extension Wine { var vintageText: String { vintage.map(String.init) ?? "-" } } |
Explanation (EN)
Objašnjenje (HR)