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
mobilecodablejsonnull-safety
Make model fields optional when the backend may omit them
If the API can return null/absent for a field, decode it as optional so decoding doesn't fail; keep only truly-guaranteed fields (like id) non-optional.
PR: mobile-mining-2026-06Created: Jul 5, 2026
Bad example
Old codeswift
| 1 | struct Cellar { let name: String; let note: String } |
Explanation (EN)
Objašnjenje (HR)
Good example
New codeswift
| 1 | struct Cellar { let id: Int; let name: String?; let note: String? } |
Explanation (EN)
Objašnjenje (HR)