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 ruleP1universalStack: mobile
mobileperformancedateformatterdry
Reuse a shared DateFormatter, don't create one per call
DateFormatter is expensive to allocate; create it once (static/shared util) and reuse it rather than instantiating per format call.
PR: mobile-mining-2026-06Created: Jul 5, 2026
Bad example
Old codeswift
| 1 | func fmt(_ d: Date) -> String { let f = DateFormatter(); f.dateFormat = "yyyy"; return f.string(from: d) } |
Explanation (EN)
Objašnjenje (HR)
Good example
New codeswift
| 1 | enum DateUtils { static let year: DateFormatter = { let f = DateFormatter(); f.dateFormat = "yyyy"; return f }() } |
Explanation (EN)
Objašnjenje (HR)