Skip to content
Back to skills

1506 View Composition Fcb97dfc

ASecurity

Keep view bodies under 10 composed elements. Extract subviews when bodies grow large.

  • 9 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added October 11, 2026
code-qualitygoswift

Works with

  • cli

Security analysis

A100/100

Scanned October 11, 2026

npx -y skills add tools-only/X-Skills --skill 1506-view-composition_fcb97dfc --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of 1506 View Composition Fcb97dfc?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for 1506 View Composition Fcb97dfc
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/tools-only-1506-view-composition-fcb97dfc/badge)](https://www.skillsdirectory.com/skills/tools-only-1506-view-composition-fcb97dfc)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

SKILL.md
# View Composition

## View Body Complexity

Keep view bodies under 10 composed elements. Extract subviews when bodies grow large.

```swift
// BAD - massive body
struct ProductView: View {
    let product: Product

    var body: some View {
        VStack {
            // 50+ lines of inline views
        }
    }
}

// GOOD - extracted subviews
struct ProductView: View {
    let product: Product

    var body: some View {
        VStack {
            PriceSection(price: product.price)
            DetailsSection(description: product.description)
        }
    }
}
```

## Computed Property Views

Avoid computed property views - they prevent SwiftUI diffing.

```swift
// BAD - can't be diffed
var priceSection: some View {
    VStack { /* content */ }
}

// GOOD - proper View struct enables diffing
struct PriceSection: View {
    let price: Decimal
    var body: some View { /* content */ }
}
```

## Modifier Ordering

Modifiers apply in order. Common patterns:

```swift
// BAD - background only covers text
Text("Hello")
    .background(.blue)
    .padding()

// GOOD - background covers padded area
Text("Hello")
    .padding()
    .background(.blue)

// BAD - shadow clipped away
RoundedRectangle()
    .shadow(radius: 5)
    .clipShape(Circle())

// GOOD - shadow visible
RoundedRectangle()
    .clipShape(Circle())
    .shadow(radius: 5)
```

## Subview Parameters

Pass simple parameters, not domain models, for reusability.

```swift
// BAD - coupled to model
struct PriceLabel: View {
    let product: Product  // Tightly coupled
}

// GOOD - model-agnostic
struct PriceLabel: View {
    let price: Decimal
    let discount: Decimal?
}
```

## Critical Anti-Patterns

| Pattern | Issue |
|---------|-------|
| `var section: some View {}` | Computed views prevent diffing |
| Body over 10 composed elements | Hard to maintain and test |
| `.background().padding()` | Wrong modifier order |
| Inline closures with complex logic | Extract to methods or views |

## Review Questions

1. Could this view body be split into smaller View structs?
2. Are there computed property views that should be View structs?
3. Is the modifier order intentional and correct?
4. Are subviews model-agnostic and reusable?

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.