SuperAPI AI Directory

swiftui-ssot

Coding & development

View repository

Updated 10-16 08:38

About this skill

SwiftUI SSOT (Single Source of Truth)

A comprehensive guide to state management and SSOT principles in SwiftUI.

Directory Structure

swiftui-ssot/
├── SKILL.md (このファイル)
└── references/
    └── ssot.md

Reference Files

references/ssot.md

A comprehensive guide to Single Source of Truth (SSOT):

  • The Three Pillars of SSOT: single source of truth, derived state, unidirectional data flow
  • Property Wrapper Selection Flowchart: @State/@Binding/@StateObject/@ObservedObject/@EnvironmentObject
  • Guide by Pattern:
    • Eliminating Duplicate State
    • Derived State (Computed Property)
    • State Lifting
    • Communication Between Sibling Views
    • Appropriate Use of EnvironmentObject
  • How to Detect Violations: code smells, search patterns
  • Implementing SSO with iOS 17+ @Observable
  • Review Checklist

How to Use

When designing state

  1. references/ssot.mdrefer to the Property Wrapper Selection Flowchart
  2. Clarify the owner of the data
  3. Do not hold derivable state

When state-related problems occur

  1. references/ssot.mdcheck the violation patterns
  2. Apply the solution for the relevant pattern

When reviewing a PR

  1. references/ssot.mduse the review checklist

The Three Pillars of SSOT

  1. Single Source of Truth: each piece of data is managed in only one place
  2. Derived State: do not hold anything that can be computed from other state
  3. Unidirectional Data Flow: pass data from parent to child; use actions from child to parent

Property Wrapper Selection Guide

Situation Recommended
Local state within a View @State
Value received from a parent (read/write) @Binding
ObservableObject owned by the View @StateObject
ObservableObject injected from outside @ObservedObject
Shared across the entire app @EnvironmentObject
iOS 17+ @Observable + @Bindable

Related Skills

  • swiftui-coding-guidelines: basic best practices
  • swift-ios-migration: iOS 17 @Observable migration