Token导航 LogoToken导航TokenDH.com
研究检索需要联网github未标认证来源可访问许可证需确认审计通过

swift-composable-architectureSwift composable 架构

Agent Skill

swift-composable-architecture 用于查找、检索和筛选相关信息,适合在 Codex、Claude、Cursor、Gemini CLI 中需要根据关键词、任务场景或来源线索快速定位候选结果时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

总安装

329

周安装

14

GitHub Stars

公开资料未说明

下载量

115
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:swift-composable-architecture(Swift composable 架构)
来源仓库:https://github.com/hocgin/agent-skills
仓库路径:skills/swift-composable-architecture
安装命令:
npx skills add https://github.com/hocgin/agent-skills --skill swift-composable-architecture
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/hocgin/agent-skills --skill swift-composable-architecture

简介

用于查找、检索和筛选相关信息。

  • 适合根据关键词、任务场景或来源线索快速定位候选结果。
  • 通过 npx skills add 命令从指定仓库安装并使用。
  • 建议确认权限范围和维护状态,注意是否会触发联网或文件读写操作。
  • swift-composable-architecture 属于研究检索类 Skill,可作为该场景下的辅助能力补充。

SKILL.md

You are an expert in The Composable Architecture (TCA) by Point-Free. Help developers write correct, testable, and composable Swift code following TCA patterns.

Core Principles

  • Unidirectional data flow: Action → Reducer → State → View
  • State as value types: Simple, equatable structs
  • Effects are explicit: Side effects return from reducers as Effect values
  • Composition over inheritance: Small, isolated, recombinable modules
  • Testability first: Every feature testable with TestStore

The Four Building Blocks

  1. State – Data for UI and logic (@ObservableState struct)
  2. Action – All events: user actions, effects, delegates (enum with @CasePathable)
  3. Reducer – Pure function evolving state, returning effects (@Reducer macro)
  4. Store – Runtime connecting state, reducer, and views (StoreOf<Feature>)

Feature Structure

import SwiftTCACore

public extension SwiftTCACore {
    enum Feature {}
}

// MARK: - 视图
extension SwiftTCACore.Feature {
    struct FeatureView: View {
        let store: StoreOf<Feature>

        var body: some View {
            List(store.items) { item in
                Text(item.title)
            }
            .onAppear { store.send(.onAppear) }
        }
    }
}

extension SwiftTCACore.Feature.FeatureView {
    @Reducer public struct Store {
        // MARK: - 状态
        @ObservableState struct State: Equatable {
            var items: IdentifiedArrayOf<Item> = []
            var isLoading = false
        }

        // MARK: - 事件
        @CasePathable enum Action {
            case onAppear
            case itemsResponse (Result<[Item], Error>)
            case delegate (Delegate)
            @CasePathable enum Delegate {
                case itemSelected (Item)
            }
        }

        @Dependency(\.apiClient) var apiClient

        var body: some ReducerOf<Self> {
            Reduce(core)
        }

        func core(into state: inout State, action: Action) -> Effect<Action> {
            switch action {
            case .onAppear:
                state.isLoading = true
                return .run {
                    send in
                    await send(.itemsResponse(Result {
                        try await apiClient.fetchItems()
                    }))
                }
            case .itemsResponse(.success(let items)):
                state.isLoading = false
                state.items = IdentifiedArray(uniqueElements: items)
                return .none
            case .itemsResponse(.failure):
                state.isLoading = false
                return .none
            case .delegate:
                return .none
            }
        }
    }
}

typealias FeatureView = SwiftTCACore.Feature.FeatureView

extension FeatureView.Store.State: @unchecked @retroactive Sendable {
    static let `default`: SwiftTCACore.Feature.FeatureView.Store.State = .init()
}

Effects

PatternUse Case
.noneSynchronous state change, no side effect
.run {send in}Async work, send actions back
.cancellable(id:)Long-running/replaceable effects
.cancel(id:)Cancel a running effect
.merge(...)Run multiple effects in parallel
.concatenate(...)Run effects sequentially

Cancellation

enum CancelID { case search }

case .searchQueryChanged(let query):
  return .run { send in
    try await clock.sleep(for: .milliseconds(300))
    await send(.searchResponse(try await api.search(query)))
  }
  .cancellable(id: CancelID.search, cancelInFlight: true)

cancelInFlight: true auto-cancels previous effect with same ID.

Dependencies

Built-in Dependencies

@Dependency(\.uuid), @Dependency(\.date), @Dependency(\.continuousClock), @Dependency(\.mainQueue)

Custom Dependencies

  1. Define client struct with closures
  2. Conform to DependencyKey with liveValue, testValue, previewValue
  3. Extend DependencyValues with computed property
  4. Use @Dependency(\.yourClient) in reducer

Test override: withDependencies {$0.apiClient.fetch = {.mock}}

Composition

Child Features

Use Scope to embed children:

var body: some ReducerOf<Self> {
  Scope(state: \.child, action: \.child) { ChildFeature() }
  Reduce { state, action in ... }
}

View: ChildView(store: store.scope(state: \.child, action: \.child))

Collections

Use IdentifiedArrayOf<ChildFeature.State> with .forEach(\.items, action: \.items) {ChildFeature()}

Navigation

Tree-Based (sheets, alerts, single drill-down)

  • Model with optional state: @Presents var detail: DetailFeature.State?
  • Action: case detail(PresentationAction<DetailFeature.Action>)
  • Reducer: .ifLet(\.$detail, action: \.detail) {DetailFeature()}
  • View: .sheet(item: $store.scope(state: \.detail, action: \.detail))

Stack-Based (NavigationStack, deep linking)

  • Model with StackState<Path.State> and StackActionOf<Path>
  • Define @Reducer enum Path {case detail(DetailFeature)...}
  • Reducer: .forEach(\.path, action: \.path)
  • View: NavigationStack(path: $store.scope(state: \.path, action: \.path))

Delegates

Child emits delegate actions for outcomes; parent responds without child knowing parent's implementation.

Testing

TestStore Basics

let store = TestStore(initialState: Feature.State()) {
  Feature()
} withDependencies: {
  $0.apiClient.fetch = { .mock }
}

await store.send(.onAppear) { $0.isLoading = true }
await store.receive(\.itemsResponse.success) { $0.isLoading = false; $0.items = [.mock] }

Key Patterns

  • Override dependencies - never hit real APIs in tests
  • Assert all state changes - mutations in trailing closure
  • Receive all effects - TestStore enforces exhaustivity
  • TestClock - control time-based effects with clock.advance(by:)
  • Integration tests - test composed parent+child features together

Higher-Order Reducers

For cross-cutting concerns (logging, analytics, metrics, feature flags):

extension Reducer {
  func analytics(_ tracker: AnalyticsClient) -> some ReducerOf<Self> {
    Reduce { state, action in
      tracker.track(action)
      return self.reduce(into: &state, action: action)
    }
  }
}

Modern TCA (2025+)

  • @Reducer macro generates boilerplate
  • @ObservableState replaces manual WithViewStore
  • @CasePathable enables key path syntax for actions (\.action.child)
  • @Dependency with built-in clients (Clock, UUID, Date)
  • @MainActor on State when SwiftUI requires it
  • Direct store access in views (no more viewStore)

Critical Rules

DO:

  • Keep reducers pure - side effects through Effect only
  • Use IdentifiedArray for collections
  • Test state transitions and effect outputs
  • Use delegates for child→parent communication

DO NOT:

  • Mutate state outside reducers
  • Call async code directly in reducers
  • Create stores inside views
  • Use @State/@StateObject for TCA-managed state
  • Skip receiving actions in tests

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

38.69%
按下载量换算44

Claude

29.02%
按下载量换算33

Cursor

19.21%
按下载量换算22

Gemini CLI

9.37%
按下载量换算11

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

需要联网

该 Skill 可能需要联网访问来源站点、仓库或外部 API;具体网络访问范围需要结合源码和 README 复核。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills