SuperAPI AI Directory

swiftui-coding-guidelines

Coding & development

View repository

Updated 10-16 09:55

About this skill

SwiftUI Coding Guidelines

Core guidelines to reference in everyday SwiftUI development.

Directory structure

swiftui-coding-guidelines/
├── SKILL.md (このファイル)
└── references/
    ├── best-practices.md      # ベストプラクティス
    ├── patterns-list.md       # 1-x: リスト・データ表示系
    ├── patterns-navigation.md # 2-x: ナビゲーション・画面遷移系
    ├── patterns-forms.md      # 3-x: フォーム・入力系
    ├── patterns-views.md      # 4-x: View構築・レイアウト系
    └── anti-patterns.md       # アンチパターン

Reference files

references/best-practices.md

Collection of SwiftUI best practices:

  • State management: Property wrappers (@State, @Binding, @StateObject, etc.)
  • Performance optimization: View structure, Lazy stacks and Grid, Equatable
  • Component design: Separation of responsibilities, Root Views vs Content Views, ViewModifier
  • Asynchronous processing: .task modifier, async/await, @MainActor
  • Navigation: NavigationStack (iOS 16+), type-safe routing
  • Layout protocol: Alternative to GeometryReader (iOS 16+)
  • Preview-driven development: Multiple-state previews

references/patterns-list.md (1-x: List/data display)

Number Pattern
1-1 Infinite scroll (Pagination)
1-2 Pull to refresh
1-3 Filtering and sorting
1-4 Swipe actions
1-5 Context menu

references/patterns-navigation.md (2-x: Navigation/screen transition)

Number Pattern
2-1 Tab view
2-2 Navigation (NavigationStack)
2-3 Modal presentation (Sheet / FullScreenCover)
2-4 Alerts and dialogs

references/patterns-forms.md (3-x: Forms/input)

Number Pattern
3-1 Search functionality (with debounce)
3-2 Form input (with validation)
3-3 Authentication screens (Login / Sign up / OTP)

references/patterns-views.md (4-x: View construction/layout)

Number Pattern
4-1 AsyncImage (with caching)
4-2 Empty state and error state
4-3 Animation
4-4 View overlapping (ZStack / overlay / background)
4-5 ContentUnavailableView(iOS 17+)

references/anti-patterns.md

Anti-patterns and solutions:

  • State management, performance, business logic
  • Asynchronous processing, navigation, memory management
  • View Identity: Unstable IDs, using indices in ForEach
  • AnyView: Performance degradation from type erasure
  • Component design: Spacing management, opacity vs if statements

Usage

When implementing something new

  1. Applicablepatterns-*.mdCheck implementation patterns in
  2. best-practices.mdCheck related best practices in
  3. anti-patterns.mdCheck patterns to avoid in

When troubleshooting

  1. anti-patterns.mdSearch for the relevant pattern in
  2. best-practices.mdCheck the recommended implementation in

Important principles

  1. Minimize state: No derivable state is held
  2. Separation of responsibilities: Separate Root Views (logic) and Content Views (UI)
  3. Performance: Appropriate use of Lazy, Equatable, and asynchronous processing
  4. ViewのIdentity: Use stable IDs, prohibit indices in ForEach
  5. Spacing is managed by the parent: Child components do not create space with padding

Related skills

  • swiftui-ssot: Detailed design of state management (SSOT)
  • swiftui-code-review-checklist: Checklist for PR review
  • swift-ios-migration: iOS 17/18, Swift 6 migration
  • swiftui-accessibility: Accessibility support