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: ios
iosswiftuistate
Own SwiftUI state with the right property wrapper
Use @State for view-local state, @StateObject to create an observable, @ObservedObject/@Binding to receive it — don't recreate a @StateObject-worthy object with @ObservedObject.
PR: mobile-canon-2026-06Created: Jul 5, 2026
Bad example
Old codeswift
| 1 | @ObservedObject var vm = ViewModel() // recreated on redraw |
Explanation (EN)
Objašnjenje (HR)
Good example
New codeswift
| 1 | @StateObject var vm = ViewModel() // created once, owned by the view |
Explanation (EN)
Objašnjenje (HR)