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

swift-composable-architectureSwift composable 架构

Agent Skill

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

总安装

1,152

周安装

48

GitHub Stars

6

下载量

384
CodexClaudeCursorGemini CLI

安装说明

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

GitHub

来源数

3

许可证

MIT

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

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

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

命令行安装

复制命令到本机终端执行。不同来源提供的安装方式可能略有差异;本站展示可直接复制的安装命令,安装前请核对来源页面。

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

简介

swift-composable-architecture 用于查找、检索和筛选相关信息。

  • 适合在 Codex、Claude、Cursor、Gemini CLI 中根据关键词或任务场景快速定位候选结果。
  • 通过 GitHub 安装,需结合原始 README 核验具体用法和权限边界。
  • 安装前建议确认维护状态及是否会触发联网、命令执行或文件读写。
  • 注意该技能当前分类为研究检索,功能以实际文档为准。

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

@Reducer
struct Feature {
  @ObservableState
  struct State: Equatable {
    var items: IdentifiedArrayOf<Item> = []
    var isLoading = false
  }

  @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 { state, action in
      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
      }
    }
  }
}

Store and View Connection

struct FeatureView: View {
  let store: StoreOf<Feature>

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

Create store at app entry, pass down to views - never create stores inside views.

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

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

04

需要参考平台分布和安装热度时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

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

能力 4

补充不同宿主或平台的使用分布数据

能力 5

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

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

平台分布

Claude Code

26.99%
按下载量换算104

Codex

26.24%
按下载量换算101

Cursor

19.54%
按下载量换算75

Antigravity

12.7%
按下载量换算49

Gemini CLI

9.25%
按下载量换算36

OpenCode

3.97%
按下载量换算15

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

需要联网

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

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。

来源信息

继续浏览同类 Skills