existential-birds/beagle / plugins/beagle-ios/skills/swiftui-code-review
swiftui-code-review
VerifiedReviews SwiftUI code for view composition, state management, performance, and accessibility. Use when reviewing .swift files containing SwiftUI views, property wrappers (@State, @Binding, @Observable), or UI code.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 2.8 KB |
| references/accessibility.md | markdown | 3.3 KB |
| references/performance.md | markdown | 3.0 KB |
| references/state-management.md | markdown | 2.7 KB |
| references/view-composition.md | markdown | 2.2 KB |
references/view-composition.md
View on GitHub# 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?
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| brainstormingobra/superpowersYou MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or planning anything new, in software or out of it (a talk, a business, a renovation). | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| brand-guidelinesanthropics/skillsApplies Anthropic's official brand colors and typography to any sort of artifact that may benefit from having Anthropic's look-and-feel. Use it when brand colors or style guidelines, visual formatting, or company design standards apply. | Stars: 197k | Updated | Claude CodeCodex | Verified | Install |
| frontend-designanthropics/skillsGuidance for distinctive, intentional visual design when building new UI or reshaping an existing one. Helps with aesthetic direction, typography, and making choices that don't read as templated defaults. | Stars: 197k | Updated | Claude CodeCodex | Verified | Install |
| mcp-builderanthropics/skillsGuide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when building MCP servers to integrate external APIs or services, whether in Python (FastMCP) or Node/TypeScript (MCP SDK). | Stars: 197k | Updated | Claude CodeCodex | Verified | Install |