AgentLint 实测验证 89/100基于 80 个 Swift 开源仓库统计

    Swift CLAUDE.md & AGENTS.md 模板

    SwiftPM 定向测试、Swift 6 严格并发安全与 SwiftLint 规范,提炼自 Swift 开源仓库。

    # Swift Project — Swift Harness
    
    Swift 6 package/app built with SwiftPM, tested with XCTest / Swift Testing, and linted with SwiftLint.
    
    ## Commands
    
    - Fast test filter: `swift test --filter TargetTests`
    - Full test suite: `swift test`
    - Lint: `swiftlint lint --strict`
    - Build: `swift build`
    
    ## Rules
    
    - Don't use force-unwraps (`!`) or `try!` outside test files. Instead use `guard let` and typed `throws`. Because unexpected nil values crash macOS/iOS apps instantly.
    - Don't touch UI state off the main actor. Instead isolate view models with `@MainActor`. Because Swift 6 strict concurrency rejects unsynchronized UI mutations.
    - When editing entitlements or signing configs, read `docs/release-signing.md`.
    
    ## Continuity
    
    - Never commit provisioning profiles, API keys, or `CLAUDE.local.md`. Log visual verification evidence in `HANDOFF.md`.

    Swift 开源生态中最常采用的工程规则

    基于 4,533 仓库研究中 80 个公开 Swift 仓库的实测统计:

    swiftui框架

    SwiftUI for UI

    49.1%28 个仓库
    unit-tests测试

    Write unit tests for all changes

    43.9%25 个仓库
    async-await-swift代码规范

    Swift async/await concurrency

    35.1%20 个仓库
    mvvm代码规范

    MVVM architecture pattern

    26.3%15 个仓库
    error-handling代码规范

    Proper error handling with context

    24.6%14 个仓库
    spm工具链

    Swift Package Manager

    22.8%13 个仓库
    conventional-commits工作流

    Use conventional commit messages

    21.1%12 个仓库
    swift-data工具链

    SwiftData for persistence

    19.3%11 个仓库
    必写验证命令(对应规则 W1 与 W7)
    安装依赖
    swift package resolve
    快速单测(秒级迭代)
    swift test --filter TargetTests
    全量测试
    swift test
    Lint 与静态检查
    swiftlint lint --strict
    生产构建
    swift build
    Swift 项目中 AI 代理常见踩坑
    • 01在生产路径滥用强解包 ! 或 try!,遇到意外 nil 直接闪退。
    • 02在后台线程修改 UI 状态未标注 @MainActor,触发 Swift 6 并发报错。

    更多实证验证模板