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: SwiftUI
swiftuireadabilitycompiler
Decompose complex SwiftUI view bodies with @ViewBuilder members
Break a large SwiftUI `body` into small `@ViewBuilder` computed properties or subviews (often in a private extension). Deeply nested single-expression bodies overwhelm the type-checker, which then reports errors at the wrong line or fails to compile; smaller pieces also read better and localize errors.
PR: profico-org-corpus batch2 (all stacks/products)Created: Jul 26, 2026
Bad example
Old codeswift
| 1 | var body: some View { |
| 2 | VStack { /* 120 lines of deeply nested header, list, footer */ } |
| 3 | } |
Explanation (EN)
One giant body makes SwiftUI's type inference slow and its errors point nowhere useful.
Objašnjenje (HR)
Good example
New codeswift
| 1 | var body: some View { |
| 2 | VStack { header; content; footer } |
| 3 | } |
| 4 |
|
| 5 | private extension FeedbackScreen { |
| 6 | @ViewBuilder var header: some View { ... } |
| 7 | @ViewBuilder var content: some View { ... } |
| 8 | @ViewBuilder var footer: some View { ... } |
| 9 | } |
Explanation (EN)
Small @ViewBuilder members compile faster and pinpoint errors.
Objašnjenje (HR)