Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Reviews, improves, and writes SwiftUI code following state management, view composition, performance, and iOS 26+ Liquid Glass best practices.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/view-structure.md
1# SwiftUI View Structure Reference23## Table of Contents45- [View Structure Principles](#view-structure-principles)6- [View File Structure (optional readability suggestion)](#view-file-structure-optional-readability-suggestion)7- [Struct or Method / Computed Property?](#struct-or-method--computed-property)8- [Prefer Modifiers Over Conditional Views](#prefer-modifiers-over-conditional-views)9- [Extract Subviews, Not Computed Properties](#extract-subviews-not-computed-properties)10- [@ViewBuilder](#viewbuilder)11- [Keep View Body Simple and Avoid High-Cost Operations](#keep-view-body-simple-and-avoid-high-cost-operations)12- [Keep View `init` Cheap](#keep-view-init-cheap)13- [Single-Child Group](#single-child-group)14- [When to Extract Subviews](#when-to-extract-subviews)15- [Container View Pattern](#container-view-pattern)16- [Utilize Lazy Containers for Large Data Sets](#utilize-lazy-containers-for-large-data-sets)17- [ZStack vs overlay/background](#zstack-vs-overlaybackground)18- [Compositing Group Before Clipping](#compositing-group-before-clipping)19- [Split State-Driven Parts into Custom View Types](#split-state-driven-parts-into-custom-view-types)20- [Reusable Styling with ViewModifier](#reusable-styling-with-viewmodifier)21- [Skeleton Loading with Redacted Views](#skeleton-loading-with-redacted-views)22- [AnyView](#anyview)23- [UIViewRepresentable Essentials](#uiviewrepresentable-essentials)24- [Troubleshooting](#troubleshooting)25- [Summary Checklist](#summary-checklist)2627## View Structure Principles2829SwiftUI's diffing algorithm compares view hierarchies to determine what needs updating. Proper view composition directly impacts performance.3031## View File Structure (optional readability suggestion)3233Property ordering has no effect on correctness or performance, so treat this as a personal/team readability preference rather than a rule. Some developers find a consistent order easier to scan — for example, environment, then state, then passed-in properties, then `init`, body, and helper subviews. Adopt it only if your team wants the consistency; never reorder existing code solely to match it.3435```swift36struct ContentView: View {37// MARK: - Environment Properties38@Environment(\.colorScheme) var colorScheme3940// MARK: - State Properties41@Binding var isToggled: Bool42@State private var viewModel: SomeViewModel4344// MARK: - Private Properties45private let title: String = "SwiftUI Guide"4647// MARK: - Initializer (if needed)48init(isToggled: Binding<Bool>) {49self._isToggled = isToggled50}5152// MARK: - Body53var body: some View {54VStack {55header56content57}58}5960// MARK: - Computed Subviews61private var header: some View {62Text(title).font(.largeTitle).padding()63}6465private var content: some View {66VStack {67Text("Counter: \(counter)")68}69}70}71```7273## Struct or Method / Computed Property?7475If a `View` is intended to be reusable across multiple screens, encapsulate it within a separate `struct`. If its usage is confined to a single context, it can be declared as a function or computed property within the containing `View`.7677However, if a view maintains state using `@State`, `@Binding`, `@ObservedObject`, `@Environment`, `@StateObject`, or similar wrappers, it should generally be a separate `struct`.7879- For simple, static views: a computed property is acceptable.80- For views requiring parameters: a method is more appropriate, but only when those parameters are stable. If parameters change per-call (e.g. inside a `ForEach` where each call receives a different item), prefer a separate `struct` so SwiftUI can diff inputs and skip body evaluation.81- For reusable, stateful, or logically independent UI sections: prefer a dedicated `struct`.8283```swift84struct ContentView: View {85var titleView: some View {86Text("Hello from Property")87.font(.largeTitle)88.foregroundColor(.blue)89}9091func messageView(text: String, color: Color) -> some View {92Text(text)93.font(.title)94.foregroundColor(color)95.padding()96}9798var body: some View {99VStack {100titleView101messageView(text: "Hello from Method", color: .red)102}103}104}105```106107## Prefer Modifiers Over Conditional Views108109**Prefer "no-effect" modifiers over conditionally including views.** When you introduce a branch, consider whether you're representing multiple views or two states of the same view.110111### Use Opacity Instead of Conditional Inclusion112113```swift114// Good - same view, different states115SomeView()116.opacity(isVisible ? 1 : 0)117118// Avoid - creates/destroys view identity119if isVisible {120SomeView()121}122```123124**Why**: Conditional view inclusion can cause loss of state, poor animation performance, and breaks view identity. Using modifiers maintains view identity across state changes.125126### When Conditionals Are Appropriate127128Use conditionals when you truly have **different views**, not different states:129130```swift131// Correct - fundamentally different views132if isLoggedIn {133DashboardView()134} else {135LoginView()136}137138// Correct - optional content139if let user {140UserProfileView(user: user)141}142```143144### Conditional View Modifier Extensions Break Identity145146A common pattern is an `if`-based `View` extension for conditional modifiers. This changes the view's return type between branches, which destroys view identity and breaks animations:147148```swift149// Problematic -- different return types per branch150extension View {151@ViewBuilder func `if`<T: View>(_ condition: Bool, transform: (Self) -> T) -> some View {152if condition {153transform(self) // Returns T154} else {155self // Returns Self156}157}158}159```160161Prefer applying the modifier directly with a ternary or always-present modifier:162163```swift164// Good -- same view identity maintained165Text("Hello")166.opacity(isHighlighted ? 1 : 0.5)167168// Good -- modifier always present, value changes169Text("Hello")170.foregroundStyle(isError ? .red : .primary)171```172173When writing new code, never reach for a `.if` modifier. When reviewing existing code that already uses one, point out the identity/animation risk and show the ternary alternative, but don't silently refactor it as part of an unrelated change — swapping it can alter behavior (state resets, transition timing) and belongs in its own focused edit.174175## Extract Subviews, Not Computed Properties176177A view is SwiftUI's unit of invalidation. When an input changes, SwiftUI re-runs the body of the smallest enclosing **view type** that depends on it — every conditional, modifier chain, and string interpolation in that body, even if only one leaf actually depends on what changed. A computed property or `@ViewBuilder` helper is inlined into the parent's body, so it shares the parent's invalidation boundary and does not reduce update cost; it only reorganizes the code. A separate `View` type with narrow inputs becomes its own boundary and re-runs only when its own inputs change.178179This is why "split your body for readability" is also a performance tool — but only when you split into real `View` types, not computed properties.180181### The Problem with @ViewBuilder Functions182183When you use `@ViewBuilder` functions or computed properties for complex views, the entire function re-executes on every parent state change:184185```swift186// BAD - re-executes complexSection() on every tap187struct ParentView: View {188@State private var count = 0189190var body: some View {191VStack {192Button("Tap: \(count)") { count += 1 }193complexSection() // Re-executes every tap!194}195}196197@ViewBuilder198func complexSection() -> some View {199// Complex views that re-execute unnecessarily200ForEach(0..<100) { i in201HStack {202Image(systemName: "star")203Text("Item \(i)")204Spacer()205Text("Detail")206}207}208}209}210```211212### The Solution: Separate Structs213214Extract to separate `struct` views. SwiftUI can skip their `body` when inputs don't change:215216```swift217// GOOD - ComplexSection body SKIPPED when its inputs don't change218struct ParentView: View {219@State private var count = 0220221var body: some View {222VStack {223Button("Tap: \(count)") { count += 1 }224ComplexSection() // Body skipped during re-evaluation225}226}227}228229struct ComplexSection: View {230var body: some View {231ForEach(0..<100) { i in232HStack {233Image(systemName: "star")234Text("Item \(i)")235Spacer()236Text("Detail")237}238}239}240}241```242243### Why This Works2442451. SwiftUI compares the `ComplexSection` struct (which has no properties)2462. Since nothing changed, SwiftUI skips calling `ComplexSection.body`2473. The complex view code never executes unnecessarily248249### Multi-section detail views250251The most common place this rule gets dropped is a detail screen with several distinct sections — `header + gallery + description + reviews`, `header + ingredients + steps`, `hero + specs + related`. The tempting shape is one big view with `private var header: some View`, `private var gallery: some View`, and so on. That shape shares one invalidation boundary, so a change that affects one section re-evaluates all of them. Factor each named section into its own `View` type that takes only the fields it renders, and keep the parent thin — it just composes the sections.252253```swift254// PREFER: each section is its own type with narrow inputs.255struct ProductDetailView: View {256let product: Product257258var body: some View {259ScrollView {260VStack(alignment: .leading, spacing: 24) {261ProductHeader(name: product.name, price: product.price)262ProductGallery(images: product.imageURLs)263ProductDescription(text: product.descriptionText)264ProductReviews(average: product.averageStars, count: product.reviewCount)265}266.padding()267}268}269}270```271272This generalizes to every `*DetailView`: one `View` type per section, narrow inputs each, a thin parent that composes them. Small `@ViewBuilder` fragments reused two or three times within the same body are still fine — the rule targets factoring done for organization or to manage body length, where a real `View` type does the right thing.273274## @ViewBuilder275276Use `@ViewBuilder` functions for small, simple sections (a few views, no expensive computation) that don't affect performance. They work particularly well for static content that doesn't depend on any `@State` or `@Binding`, since SwiftUI won't need to diff them independently. Extract to a separate `struct` when the section is complex, depends on state, or needs to be skipped during re-evaluation.277278The `@ViewBuilder` attribute is only required when a function or computed property returns multiple different views conditionally, for example through `if` or `switch`:279280```swift281@ViewBuilder282private var conditionalView: some View {283if isExpanded {284VStack {285Text("Expanded View")286Image(systemName: "star")287}288} else {289Text("Collapsed View")290}291}292```293294If every branch returns the same concrete type, `@ViewBuilder` is unnecessary:295296```swift297var conditionalText: some View {298if Bool.random() {299Text("Hello")300} else {301Text("World")302}303}304```305306Prefer `@ViewBuilder` when:307308- there is conditional branching between multiple view types309- extracting a separate `struct` would not provide meaningful separation310311## Keep View Body Simple and Avoid High-Cost Operations312313Refrain from performing complex operations within the `body` of your view. Instead of passing a ready-to-use sequence with filtering, mapping, or sorting directly into `ForEach`, prepare the sequence outside the body.314315```swift316// Avoid such things ...317var body: some View {318List {319ForEach(model.values.filter { $0 > 0 }, id: \.self) {320Text(String($0))321.padding()322}323}324}325```326327Prefer:328329```swift330struct FilteredListView: View {331private let filteredValues: [Int]332333init(values: [Int]) {334self.filteredValues = values.filter { $0 > 0 } // Perform filtering once335}336337var body: some View {338List {339content340}341}342343private var content: some View {344ForEach(filteredValues, id: \.self) { value in345Text(String(value))346.padding()347}348}349}350```351352The reason this matters is that the system can call `body` multiple times during a single layout phase. Complex body computation makes those calls more expensive than necessary.353354General guidance:355356- avoid filtering, sorting, and mapping inline in `body`357- avoid constructing expensive formatters in `body`358- avoid heavy branching in large view trees359- move data preparation into the model layer or dedicated helpers360361## Keep View `init` Cheap362363A view's `init` runs every time the parent re-evaluates its body, which can be many times per second for views inside `List`, `LazyVStack`, scroll containers, or animated parents. Treat `init` as a constant-time copy of inputs into stored properties. Don't decode JSON, build a `DateFormatter`, touch the file system, or allocate large structures there — that work repeats on every parent body pass even when the inputs are identical.364365```swift366// AVOID: decoding and formatting on every init367init(rawJSON: Data, date: Date) {368self.summary = try! JSONDecoder().decode(WeatherSummary.self, from: rawJSON)369let formatter = DateFormatter()370formatter.dateStyle = .medium371self.formattedDate = formatter.string(from: date)372}373374// PREFER: take already-prepared values; format lazily in body375let summary: WeatherSummary376let date: Date377378var body: some View {379VStack {380Text(summary.headline)381Text(date, format: .dateTime.day().month().year()) // cached, locale-aware382}383}384```385386If a derived value genuinely needs to be computed once and kept, store it on an `@State`-owned `@Observable` model or compute it asynchronously in `.task` — not in `init`. `init` is not a one-time setup hook; it runs as often as the parent's body does.387388## Single-Child Group389390`Group { SomeView() }` — a `Group` with exactly one concrete child — wraps the view in an extra `Group<SomeView>` type for no visual benefit. Every modifier chained after it must be type-checked against that wrapper, adding avoidable type-checking overhead in long chains. Drop the `Group` and chain modifiers directly on the child.391392```swift393// AVOID: single concrete child wrapped in Group394Group { Text(status) }395.padding(.horizontal, 8)396.background(.thinMaterial, in: Capsule())397398// PREFER: chain directly on the child399Text(status)400.padding(.horizontal, 8)401.background(.thinMaterial, in: Capsule())402```403404The rule is specifically about one concrete view. A `Group` whose content is a `ForEach`, multiple sibling views, or an `if`/`else` (which produces `_ConditionalContent`) is doing real work — applying a shared modifier across siblings or both branches — and is fine.405406## When to Extract Subviews407408Extract complex views into separate subviews when:409- The view has multiple logical sections or responsibilities410- The view contains reusable components411- The view body becomes difficult to read or understand412- You need to isolate state changes for performance413- The view is becoming large (keep views small for better performance)414- The section may evolve independently over time415416## Container View Pattern417418### Avoid Closure-Based Content419420Closures can't be compared, causing unnecessary re-renders:421422```swift423// BAD - closure prevents SwiftUI from skipping updates424struct MyContainer<Content: View>: View {425let content: () -> Content426427var body: some View {428VStack {429Text("Header")430content() // Always called, can't compare closures431}432}433}434435// Usage forces re-render on every parent update436MyContainer {437ExpensiveView()438}439```440441### Use @ViewBuilder Property Instead442443```swift444// GOOD - view can be compared445struct MyContainer<Content: View>: View {446@ViewBuilder let content: Content447448var body: some View {449VStack {450Text("Header")451content // SwiftUI can compare and skip if unchanged452}453}454}455456// Usage - SwiftUI can diff ExpensiveView457MyContainer {458ExpensiveView()459}460```461462## Utilize Lazy Containers for Large Data Sets463464When displaying extensive lists or grids, prefer `LazyVStack`, `LazyHStack`, `LazyVGrid`, or `LazyHGrid`. These containers load views only when they appear on the screen, reducing memory usage and improving performance.465466```swift467struct ContentView: View {468let items = Array(0..<1000)469470var body: some View {471ScrollView {472LazyVStack {473ForEach(items, id: \.self) { item in474Text("Item \(item)")475}476}477}478}479}480```481482Prefer lazy containers when:483484- rendering large collections485- row views are non-trivial486- memory usage matters487- the content is inside `ScrollView`488489## ZStack vs overlay/background490491Use `ZStack` to **compose multiple peer views** that should be layered together and jointly define layout.492493Prefer `overlay` / `background` when you’re **decorating a primary view**.494Not primarily because they don’t affect layout size, but because they **express intent and improve readability**: the view being modified remains the clear layout anchor.495496A key difference is **size proposal behavior**:497- In `overlay` / `background`, the child view implicitly adopts the size proposed to the parent when it doesn’t define its own size, making decorative attachments feel natural and predictable.498- In `ZStack`, each child participates independently in layout, and no implicit size inheritance exists. This makes it better suited for peer composition, but less intuitive for simple decoration.499500Use `ZStack` (or another container) when the “decoration” **must explicitly participate in layout sizing**—for example, when reserving space, extending tappable/visible bounds, or preventing overlap with neighboring views.501502### Examples503504```swift505// GOOD - decoration via overlay (layout anchored to button)506Button("Continue") { }507.overlay(alignment: .trailing) {508Image(systemName: "lock.fill").padding(.trailing, 8)509}510511// BAD - ZStack when overlay suffices (layout no longer anchored to button)512ZStack(alignment: .trailing) {513Button("Continue") { }514Image(systemName: "lock.fill").padding(.trailing, 8)515}516517// GOOD - background shape takes parent size518HStack(spacing: 12) { Text("Inbox"); Text("Next") }519.background { Capsule().strokeBorder(.blue, lineWidth: 2) }520```521522## Compositing Group Before Clipping523524**Always add `.compositingGroup()` before `.clipShape()` when clipping layered views (`.overlay` or `.background`).** Without it, each layer is antialiased separately and then composited. Where antialiased edges overlap — typically at rounded corners — you get visible color fringes (semi-transparent pixels of different colors blending together).525526```swift527let shape = RoundedRectangle(cornerRadius: 16)528529// BAD - each layer antialiased separately, producing color fringes at corners530Color.red531.overlay(.white, in: shape)532.clipShape(shape)533.frame(width: 200, height: 150)534535// GOOD - layers composited first, antialiasing applied once during clipping536Color.red537.overlay(.white, in: .rect)538.compositingGroup()539.clipShape(shape)540.frame(width: 200, height: 150)541```542543`.compositingGroup()` forces all child layers to be rendered into a single offscreen buffer before the clip is applied. This means antialiasing only happens once — on the final composited result — eliminating the fringe artifacts.544545## Split State-Driven Parts into Custom View Types546547Large views often depend on multiple independent state sources. If a single view body depends on all of them, then any state change can cause the entire body to re-evaluate.548549```swift550struct BigAndComplicatedView: View {551@State private var counter = 0552@State private var isToggled = false553@StateObject private var viewModel = SomeViewModel()554555let title = "Big and Complicated View"556557var body: some View {558VStack {559Text(title)560.font(.largeTitle)561562Text("Counter: \(counter)")563.font(.title)564565Toggle("Enable Feature", isOn: $isToggled)566.padding()567568Button("Increment Counter") {569counter += 1570}571572Text("ViewModel Data: \(viewModel.data)")573.padding()574575Button("Fetch Data") {576viewModel.fetchData()577}578}579}580}581```582583### Better: Split Into Smaller Components584585```swift586struct BigAndComplicatedView: View {587@State private var counter = 0588@State private var isToggled = false589@StateObject private var viewModel = SomeViewModel()590591var body: some View {592VStack {593titleView594CounterView(counter: $counter)595ToggleView(isToggled: $isToggled)596ViewModelDataView(data: viewModel.data) {597viewModel.updateData()598}599.equatable()600}601}602603private var titleView: some View {604Text("Big and Complicated View")605.font(.largeTitle)606}607}608```609610Why this is better:611612- changing `counter` only affects `CounterView`613- toggling only affects `ToggleView`614- updating the model data only affects `ViewModelDataView`615616### Notes on Equatable617618Using `Equatable` for a view is not a universal best practice, but it can be useful in targeted cases where:619620- the input is small and well-defined621- the comparison logic is meaningful622- you want to reduce unnecessary body evaluation for a specific subtree623624Do not use `Equatable` as a blanket optimization technique.625626## Reusable Styling with ViewModifier627628Extract repeated modifier combinations into a `ViewModifier` struct. Expose via a `View` extension for autocompletion:629630```swift631private struct CardStyle: ViewModifier {632func body(content: Content) -> some View {633content634.padding()635.background(Color(.secondarySystemBackground))636.clipShape(.rect(cornerRadius: 12))637}638}639640extension View {641func cardStyle() -> some View {642modifier(CardStyle())643}644}645```646647### Custom ButtonStyle648649Use the `ButtonStyle` protocol for reusable button designs. Use `PrimitiveButtonStyle` only when you need custom interaction handling (e.g., simultaneous gestures):650651```swift652struct PrimaryButtonStyle: ButtonStyle {653func makeBody(configuration: Configuration) -> some View {654configuration.label655.bold()656.foregroundStyle(.white)657.padding(.horizontal, 16)658.padding(.vertical, 8)659.background(Color.accentColor)660.clipShape(Capsule())661.scaleEffect(configuration.isPressed ? 0.95 : 1)662.animation(.smooth, value: configuration.isPressed)663}664}665```666667### Discoverability with Static Member Lookup668669Make custom styles and modifiers discoverable via leading-dot syntax:670671```swift672extension ButtonStyle where Self == PrimaryButtonStyle {673static var primary: PrimaryButtonStyle { .init() }674}675676// Usage: .buttonStyle(.primary)677```678679This pattern works for any SwiftUI style protocol (`ButtonStyle`, `ListStyle`, `ToggleStyle`, etc.).680681## Skeleton Loading with Redacted Views682683Use `.redacted(reason: .placeholder)` to show skeleton views while data loads. Use `.unredacted()` to opt out specific views:684685```swift686VStack(alignment: .leading) {687Text(article?.title ?? String(repeating: "X", count: 20))688.font(.headline)689Text(article?.author ?? String(repeating: "X", count: 12))690.font(.subheadline)691Text("SwiftLee")692.font(.caption)693.unredacted()694}695.redacted(reason: article == nil ? .placeholder : [])696```697698Apply `.redacted` on a container to redact all children at once.699700## AnyView701702`AnyView` is type erasure. SwiftUI uses structural identity based on type information to determine when views should be updated.703704```swift705private var nameView: some View {706if isEditable {707TextField("Your name", text: $name)708} else {709Text(name)710}711}712```713714Avoid patterns like:715716```swift717private var nameView: some View {718if isEditable {719return AnyView(TextField("Your name", text: $name))720} else {721return AnyView(Text(name))722}723}724```725726Because `AnyView` erases type information, SwiftUI loses some optimization opportunities. Prefer `@ViewBuilder` or conditional branches with concrete view types.727728Use `AnyView` only when type erasure is truly necessary for API design.729730## UIViewRepresentable Essentials731732When bridging UIKit views into SwiftUI:733734- `makeUIView(context:)` is called **once** to create the UIKit view735- `updateUIView(_:context:)` is called on **every SwiftUI redraw** to sync state736- The representable struct itself is **recreated on every redraw** -- avoid heavy work in its init737- Use a `Coordinator` for delegate callbacks and two-way communication738739```swift740struct MapView: UIViewRepresentable {741let coordinate: CLLocationCoordinate2D742743func makeUIView(context: Context) -> MKMapView {744let map = MKMapView()745map.delegate = context.coordinator746return map747}748749func updateUIView(_ map: MKMapView, context: Context) {750map.setCenter(coordinate, animated: true)751}752753func makeCoordinator() -> Coordinator { Coordinator() }754755class Coordinator: NSObject, MKMapViewDelegate { }756}757```758759## Troubleshooting760761### Debug SwiftUI Renderings762763> See `references/performance-patterns.md` (item #8) for the `_printChanges()` vs `_logChanges()` comparison and the `@self`/`@identity` output meaning. The snippets below show the call sites.764765If it is needed to debug render cycles and read console output you can leverage the `_printChanges()` or `_logChanges()` methods on `View`. These methods print information about when the view is being evaluated and what changes are triggering updates. This can be very helpful when your view body is called multiple times and you want to know why.766767```swift768struct ContentView: View {769@State private var counter: Int = 99770771init() {772print(Self.self, #function)773}774775var body: some View {776let _ = Self._printChanges()777778VStack {779Text("Counter: \(counter)")780Button {781counter += 1782} label: {783Text("Counter +1")784}785.buttonStyle(.borderedProminent)786}787.padding()788}789}790```791792As an alternative to `Self._printChanges()`, you can use `_logChanges()`793794```swift795struct ContentView: View {796@State private var counter: Int = 99797798var body: some View {799let _ = Self._logChanges()800801VStack {802Text("Counter: \(counter)")803Button {804counter += 1805} label: {806Text("Counter +1")807}808.buttonStyle(.borderedProminent)809}810.padding()811}812}813```814815Use these tools only for debugging and remove them from production code.816817### Handling "The Compiler Is Unable to Type-Check This Expression in Reasonable Time"818819If you encounter:820821> The compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressions822823it is often caused by overly complex view structures or expressions.824825Ways to fix it:826827- break large expressions into smaller computed values828- extract subviews829- split long modifier chains830- simplify nested generics and builders831- avoid huge inline closures832833## Summary Checklist834835- [ ] Prefer modifiers over conditional views for state changes836- [ ] Avoid `if`-based conditional modifier extensions (they break view identity)837- [ ] Extract complex views into separate subviews, not computed properties838- [ ] Keep views small for readability and performance839- [ ] Use `@ViewBuilder` only where it actually adds value840- [ ] Avoid heavy filtering, mapping, sorting, or formatter creation inside `body`841- [ ] Keep view `init` cheap (no decoding/formatting/allocation; it runs on every parent body pass)842- [ ] Avoid single-child `Group { OneView() }` (chain modifiers directly on the child)843- [ ] Use lazy containers for large data sets844- [ ] Container views use `@ViewBuilder let content: Content`845- [ ] Prefer `overlay` / `background` for decoration and `ZStack` for peer composition846- [ ] `.compositingGroup()` before `.clipShape()` on layered views to avoid antialiasing fringes847- [ ] Split state-heavy areas into smaller view types848- [ ] Extract repeated styling into `ViewModifier` or `ButtonStyle`849- [ ] Expose reusable styles via static member lookup when it improves discoverability850- [ ] Use `.redacted(reason: .placeholder)` for loading skeletons851- [ ] Avoid `AnyView` unless type erasure is truly needed852- [ ] In `UIViewRepresentable`, keep heavy work out of struct init853- [ ] Use `_printChanges()` / `_logChanges()` to debug rendering behavior854- [ ] Break up overly complex expressions when the compiler struggles855