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

swift-modern-architecture-skillSwift modern 架构技能

Agent Skill

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

总安装

612

周安装

26

GitHub Stars

公开资料未说明

下载量

214
CodexClaudeCursorGemini CLI

安装说明

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

GitHub

来源数

2

许可证

MIT

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

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

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

命令行安装

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

AgentSkills.tonpx skills
npx skills add pstuart/pstuart --skill "swift-modern-architecture-skill"

简介

用于查找、检索和筛选相关信息,支持基于关键词快速定位候选结果。

  • 适用于 Codex、Claude、Cursor 和 Gemini CLI 中的研究检索场景。
  • 可结合来源仓库 README 核验具体用法和功能边界。
  • 安装前需确认权限范围和维护状态,避免触发不必要的联网操作。
  • 建议评估是否会执行命令或读写文件后再部署使用。

SKILL.md

name
swift-modern-architecture-skill
description
Guide for building iOS apps using Swift 6, iOS 18+, SwiftUI, SwiftData, and modern concurrency patterns. Use when writing Swift/iOS code, designing app architecture, or modernizing legacy patterns. Prevents outdated patterns like Core Data, ObservableObject, DispatchQueue, and NavigationView.

Swift Modern Architecture Skill

Build iOS apps using Swift 6 and iOS 18+ best practices. This skill ensures code uses modern patterns: SwiftData (not Core Data), Observation framework (not Combine), Swift concurrency (not GCD), and current SwiftUI APIs.

Core Principles

1. Swift 6 Concurrency First

Always use Swift concurrency (async/await, actor, @MainActor) instead of GCD or completion handlers. Use structured concurrency (TaskGroup, async let) over unstructured tasks.

2. Observation Framework Over Combine

Use @Observable macro for state management instead of ObservableObject with @Published. The Observation framework is more efficient and has cleaner syntax.

3. SwiftData Over Core Data

For new projects, always use SwiftData with @Model and @Query. SwiftData provides simpler APIs while maintaining Core Data's power.

4. Modern SwiftUI APIs

Use NavigationStack (not NavigationView), @Entry for environment values, .task modifier for async work, and built-in components like ContentUnavailableView.

5. Type Safety

Use enums instead of strings for identifiers, typed throws for specific errors, and proper Sendable conformance for thread safety.

6. Value Types When Possible

Prefer structs and enums over classes unless reference semantics are required. Use actor for thread-safe shared mutable state.

When to Use This Skill

Activate this skill when:

  • Writing Swift or iOS application code
  • Designing application architecture
  • Reviewing or modernizing existing Swift code
  • Setting up SwiftUI views, view models, or data models
  • Implementing networking, persistence, or business logic
  • Working with async operations or concurrency

Architecture Pattern: MVVM with Observation

View Model Structure

@Observable
final class ViewModel {
    // Private dependencies
    private let service: ServiceProtocol
    
    // Public readable state
    private(set) var data: [Item] = []
    private(set) var isLoading = false
    private(set) var error: Error?
    
    // User input state (use @Bindable in view)
    var searchText = ""
    var selectedFilter: Filter = .all
    
    init(service: ServiceProtocol) {
        self.service = service
    }
    
    // Public actions
    func loadData() async {
        isLoading = true
        defer { isLoading = false }
        
        do {
            data = try await service.fetchData()
        } catch {
            self.error = error
        }
    }
}

View Structure

struct ContentView: View {
    @Bindable var viewModel: ViewModel
    
    var body: some View {
        content
            .task { await viewModel.loadData() }
    }
    
    @ViewBuilder
    private var content: some View {
        if viewModel.isLoading {
            ProgressView()
        } else {
            List(viewModel.data) { item in
                ItemRow(item: item)
            }
        }
    }
}

SwiftData Quick Reference

Model Definition

import SwiftData

@Model
final class Item {
    var name: String
    var createdAt: Date
    @Relationship(deleteRule: .cascade) var children: [ChildItem]
    
    init(name: String) {
        self.name = name
        self.createdAt = Date()
        self.children = []
    }
}

Querying Data

// In SwiftUI view
@Query(sort: \Item.createdAt, order: .reverse) 
private var items: [Item]

// With filter
@Query(filter: #Predicate<Item> { $0.isComplete }) 
private var completedItems: [Item]

// With dynamic predicate
@Query private var items: [Item]

init(searchText: String) {
    let predicate = #Predicate<Item> { item in
        searchText.isEmpty || item.name.contains(searchText)
    }
    _items = Query(filter: predicate)
}

Model Context Operations

@Environment(\.modelContext) private var modelContext

func addItem() {
    let item = Item(name: "New")
    modelContext.insert(item)
    try? modelContext.save()
}

func deleteItem(_ item: Item) {
    modelContext.delete(item)
    try? modelContext.save()
}

API Client Pattern

Create an actor for thread-safe API operations:

actor APIClient {
    private let session: URLSession
    private let decoder: JSONDecoder
    
    init(session: URLSession = .shared) {
        self.session = session
        self.decoder = JSONDecoder()
    }
    
    func fetch<T: Decodable>(_ endpoint: Endpoint) async throws -> T {
        let (data, response) = try await session.data(for: endpoint.urlRequest)
        
        guard let httpResponse = response as? HTTPURLResponse,
              (200...299).contains(httpResponse.statusCode) else {
            throw APIError.invalidResponse
        }
        
        return try decoder.decode(T.self, from: data)
    }
}

Navigation Pattern

Use type-safe navigation with NavigationStack:

struct AppView: View {
    @State private var path = NavigationPath()
    
    var body: some View {
        NavigationStack(path: $path) {
            RootView()
                .navigationDestination(for: Item.self) { item in
                    ItemDetailView(item: item)
                }
                .navigationDestination(for: User.self) { user in
                    UserProfileView(user: user)
                }
        }
    }
}

Testing with Swift Testing

Use the modern Swift Testing framework instead of XCTest:

import Testing

@Test("View model loads data successfully")
func dataLoading() async throws {
    let viewModel = ViewModel(service: MockService())
    await viewModel.loadData()
    #expect(viewModel.data.isEmpty == false)
}

@Test("Validation fails with invalid input", arguments: [
    "invalid-email",
    "missing@",
    "@domain.com"
])
func emailValidation(invalidEmail: String) throws {
    #expect(throws: ValidationError.self) {
        try validateEmail(invalidEmail)
    }
}

Common Modernization Checks

Before writing code, verify you're using:

  • @Observable NOT ObservableObject
  • @Query NOT @FetchRequest
  • NavigationStack NOT NavigationView
  • async/await NOT completion handlers
  • @MainActor NOT DispatchQueue.main.async
  • actor NOT serial DispatchQueue
  • SwiftData.ModelContext NOT NSManagedObjectContext
  • ✅ Swift Testing @Test NOT XCTest
  • ✅ Typed throws(ErrorType) when appropriate

Bundled Resources

References

Load when you need detailed guidance:

  • modern-patterns.md - Comprehensive patterns for Swift 6/iOS 18+

- Load when: Implementing any feature, especially concurrency, data persistence, or API calls

  • anti-patterns.md - What NOT to do and why

- Load when: Reviewing code, modernizing legacy patterns, or unsure about approach

  • examples.md - Complete working implementations

- Load when: Starting new features (Todo app, Weather app, Auth flow examples)

Usage Pattern

  1. Read the relevant reference file before implementing complex features
  2. Check anti-patterns when reviewing existing code
  3. Reference complete examples when starting new app components

Quick Decision Tree

Need state management? → Use @Observable for view models → Use @State for simple view-local state → Use @Environment for dependency injection

Need data persistence? → Use SwiftData with @Model and @Query → Never use Core Data for new code

Need async operations? → Use async/await and structured concurrency → Mark UI-bound code with @MainActor → Use actor for thread-safe shared state

Need navigation? → Use NavigationStack with NavigationPath → Type-safe destinations with .navigationDestination(for:)

Need API calls? → Create an actor with async throws methods → Use URLSession.data(from:) with async/await

Error Prevention

This skill actively prevents these outdated patterns:

  • Core Data (NSManagedObject, @FetchRequest)
  • Combine (ObservableObject, @Published, .sink)
  • GCD (DispatchQueue, DispatchGroup)
  • Old SwiftUI (NavigationView, NavigationLink(destination:))
  • Manual threading (Thread, NSOperationQueue)
  • Completion handlers when async/await is available
  • XCTest when Swift Testing is more appropriate

When encountering these patterns in existing code, suggest modern alternatives from the references.

适合场景

01

用户想查找某类 Agent Skill 时

02

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

03

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

04

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

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

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

能力 4

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

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

平台分布

windsurf

30.3%
按下载量换算65

Cursor

24.99%
按下载量换算53

Codex

15.8%
按下载量换算34

Claude Code

13.97%
按下载量换算30

Antigravity

7.41%
按下载量换算16

Gemini CLI

3.15%
按下载量换算7

安全审计

暂无安全审计结果可展示。

权限和风险

需要联网

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

安装前确认

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

来源信息

继续浏览同类 Skills