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 ruleP0stack specificStack: ios
iosmemoryretain-cycleclosures
Capture self weakly in escaping closures to avoid retain cycles
Strongly capturing self in a stored/escaping closure creates a retain cycle and leaks; use [weak self] and guard it.
PR: mobile-canon-2026-06Created: Jul 5, 2026
Bad example
Old codeswift
| 1 | api.load { self.items = $0 } |
Explanation (EN)
Objašnjenje (HR)
Good example
New codeswift
| 1 | api.load { [weak self] in self?.items = $0 } |
Explanation (EN)
Objašnjenje (HR)