swift-development
Skill3 starsChanged 23 days agoMITView on GitHub
提供 Swift 6+ 核心语言开发能力,涵盖并发编程、宏、数据模型设计和业务逻辑实现。使用此技能编写 ViewModel、Service 或 Repository 层代码、定义数据模型、实现算法、编写单元测试,或修复并发警告和数据竞争时使用。
Files
Swift 6 开发技能
何时使用
触发场景:当用户提出以下请求时,使用本 skill:
- 当需要编写 ViewModel、Service 或 Repository 层代码时
- 当需要定义数据模型或实现算法时
- 当用户要求修复并发警告或数据竞争时
指令
当处理非 UI 的 Swift 代码、业务逻辑、算法或数据层时,请遵循本指南。你的目标是编写高性能、线程安全且富有表现力的 Swift 代码。
此技能的功能
- 并发编程: 使用 Actors, async/await, Task, TaskGroup 编写安全并发代码。
- 类型安全: 定义 Sendable 类型,使用 Typed Throws 精确处理错误。
- 测试: 使用 Swift Testing 框架编写现代化的单元测试。
- 数据处理: 编写 Codable 模型,进行 JSON 解析和网络请求封装。
- 宏的使用: 使用或创建宏来减少样板代码。
何时使用此技能
- 编写 ViewModel, Service, Repository 层代码时。
- 定义数据模型 (structs, enums) 时。
- 实现算法或工具函数时。
- 编写单元测试时。
- 修复并发警告或数据竞争问题时。
示例
示例 1:定义安全的 Actor 服务
/// 一个线程安全的用户数据服务
actor UserService {
private var cache: [String: User] = [:]
// 使用 typed throws 明确错误类型
func fetchUser(id: String) async throws(NetworkError) -> User {
if let cached = cache[id] {
return cached
}
// 模拟网络请求
let user = try await NetworkClient.shared.get("/users/\(id)", as: User.self)
cache[id] = user
return user
}
}示例 2:使用 Swift Testing 进行测试
import Testing
@testable import MyApp
@Test("User parsing should succeed")
func userParsing() async throws {
let json = """
{ "id": "1", "name": "Alice" }
""".data(using: .utf8)!
let user = try JSONDecoder().decode(User.self, from: json)
#expect(user.name == "Alice")
#expect(user.id == "1")
}最佳实践
- Conform to Sendable: 任何在并发域之间传递的类型都应遵循
Sendable协议。 - Avoid Global Mutable State: 避免使用全局变量,除非它们由 Actor 保护。
- Implicitly Unwrapped Optionals: 严禁使用强制解包操作符,除非在初始化器中确实无法避免(极少见)。
- Use
letovervar: 默认使用常量,仅在必要时使用变量。 - Error Handling: 优先使用
throws和do-catch,而不是返回Optional或Result类型(在 async 上下文中 throws 更自然)。
备注
- 始终留意编译器关于并发的警告(Strict Concurrency Checking)。
- 在处理跨 Actor 边界的闭包时,注意捕获列表
[weak self]或[unowned self]的使用(但在 Task 中通常不需要 weak,除非为了打破循环引用)。
Other versions2 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 2
- sammcj/agentic-coding★ 164same name
- hmohamed01/swift-development★ 60same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository37 other files it gives its agents.
- api-designSkill
- database-designSkill
- design-patternSkill
- enterprise-javaSkill
- frontend-reactSkill
- frontend-svelteSkill
- frontend-vueSkill
- git-guruSkill
- go-developmentSkill
- javascript-typescriptSkill
- product-managementSkill
- python-developmentSkill
- session-summarySkill
- swift-developmentSkill
- swiftui-developmentSkill
- system-architectureSkill
- tech-documentationSkill
- testingSkill
- xcode-managementSkill
- api-designSkill
- database-designSkill
- design-patternSkill
- enterprise-javaSkill
- frontend-reactSkill
- frontend-svelteSkill
- frontend-vueSkill
- git-guruSkill
- go-developmentSkill
- javascript-typescriptSkill
- product-managementSkill
- python-developmentSkill
- session-summarySkill
- swiftui-developmentSkill
- system-architectureSkill
- tech-documentationSkill
- testingSkill
- xcode-managementSkill
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
Reviews can't be read right now.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

