write-swift
Skill12 starsChanged 6 days agoMITView on GitHub
写、审查或迁移 Swift 时读:Swift 6.2 起的并发规则、默认主线程隔离、数据竞争的修法,以及模型常写成旧样子的新写法
30 other projects use a version of this.
Adopted by
Most recently taken up by
- 1-Pankaj/AutonomousMarketingtheir own version, first seen Nov 8, 2026
- Tresnanda/kyberntheir own version, first seen Nov 8, 2026
- leepokai/Codynctheir own version, first seen Nov 4, 2026
- HackIndiaXYZ/ai-first-startup-hackathon-build-a-startup-using-ai-only-arclighttheir own version, first seen Nov 1, 2026
- orrrrli/ai-engineering-stacktheir own version, first seen Nov 1, 2026
- LuanRoger/next-dxtheir own version, first seen Nov 1, 2026
Used with
Projects with it also use image-to-code, brandkit and 10 more.
Other files people use alongside this one.
Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
OpenAISkillimage-to-code
Implement a selected image, screenshot, mockup, or Image Gen reference as a faithful, responsive frontend.
Also in 7 projects that use this
AnasX7Skillbrandkit
Premium brand-kit image generation skill for creating high-end brand-guidelines boards, logo systems, identity decks, and visual-world presentations. Trained for minimalist, cinematic, editorial, dark-tech, luxury, cultural, security, gaming, developer-tool, and consumer-app brand systems. Optimized for intentional logo concepting, refined composition, sparse typography, strong symbolic meaning, premium mockups, art-directed imagery, and flexible grid layouts.
Also in 6 projects that use this
HK-hubSkillstitch-design-taste
Semantic Design System Skill for Google Stitch. Generates agent-friendly DESIGN.md files that enforce premium, anti-generic UI standards — strict typography, calibrated color, asymmetric layouts, perpetual micro-motion, and hardware-accelerated performance.
Also in 5 projects that use this
HK-hubSkilldesign-taste-frontend-v1
The original v1 taste-skill, preserved for projects depending on its exact behavior. The current default is `design-taste-frontend` (v2 experimental), which is a substantial rewrite. Use this v1 install name only if you need exact backward compatibility.
Also in 4 projects that use this
AnasX7Skillindustrial-brutalist-ui
Raw mechanical interfaces fusing Swiss typographic print with military terminal aesthetics. Rigid grids, extreme type scale contrast, utilitarian color, analog degradation effects. For data-heavy dashboards, portfolios, or editorial sites that need to feel like declassified blueprints.
Also in 5 projects that use this
- +7 more from AnasX7
Other versions30 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 30
- emilkowalski/skill★ 55ksame name
- emilkowalski/skills★ 55ksame name
- KartikLabhshetwar/better-shot★ 2.4ksame name
- leepokai/Codync★ 2ksame name
- Tresnanda/kybern★ 83same name
- anis-dr/skills★ 3same name
- idexal/idexal-skills★ 2same name
- orrrrli/ai-engineering-stack★ 2same name
- orrrrli/clawd-harness★ 2same name
- sanmidable/skills★ 2same name
20 more not listed
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 repository28 other files it gives its agents.
- AGENTS.mdAGENTS.md
- gpt-imageSkill
- postSkill
- promoSkill
- videoSkill
- cuepadSkill
- architecture-auditSkill
- better-testSkill
- project-setupSkill
- prototypeSkill
- prSkill
- shipSkill
- ui-craftSkill
- ui-picksSkill
- better-browser-useSkill
- better-computer-useSkill
- herdrSkill
- sshSkill
- researchSkill
- session-dataSkill
- web-searchSkill
- fan-outSkill
- grillingSkill
- hillclimbSkill
- retroSkill
- eli5Skill
- writing-for-agentsSkill
- writing-for-humansSkill
The file
Files
Write Swift
以项目工具链为准:下文到 Swift 6.3 都可用;标 ⚠ 的属于未发布的 6.4,确认工具链后才用。
默认
从最简单、最静态、单线程的写法起步,说得出理由才往下走一档:
struct/enum优先于class;互斥状态用一个enum,不用一组可选属性。- 具体类型优先;出现跨类型的重复代码才抽协议,没有逐类型定制的协议改成约束扩展。
some P优先;要存放异构类型才用any P。- 主线程同步代码优先;Instruments 显示卡顿才
async→@concurrent→actor。
并发(Swift 6.2 起)
async不再自动离开当前 actor,在调用处的隔离上运行。把自己的计算挪到后台用@concurrent;库 API 用nonisolated,让调用方决定在哪跑。- App 与界面模块开 Approachable Concurrency 和 Default Actor Isolation = MainActor(包里
.defaultIsolation(MainActor.self));通用库不开。开了之后类型与函数上不再写@MainActor,只在默认隔离管不到处写:函数类型与回调参数、nonisolated类型里的成员、非主线程回调里起的Task。 - 修数据竞争按顺序:不共享(每个并发任务用自己的实例)→ 改成 Sendable 值类型 → 隔离到 actor → 最后才用
Synchronization的Mutex/Atomic(放在let里)或@unchecked Sendable。不用NSLock、DispatchSemaphore;跨await不持锁。 - 每个
await都是挂起点,回来后重新检查前提;actor 的状态修改放在同步段里,actor 不保证先进先出。 - 结构化并发优先:固定个数用
async let,动态个数用有上限的withTaskGroup,无返回值用withDiscardingTaskGroup;Task {}只给挂在界面事件上的工作,几乎不用Task.detached。取消是协作的,开始昂贵工作前检查。 - 回调桥接:
withCheckedContinuation每条路径恰好 resume 一次;委托式 API 包成AsyncStream,在onTermination里清理。 - SwiftUI 签名带
@Sendable的闭包(visualEffect、Shape.path、Layout、onGeometryChange)可能不在主线程:捕获要用的值,不捕获self。手势、滚动回调里的动画状态同步改,长耗时工作再开Task。
新写法
| 不写 | 写 |
ObservableObject + @Published | @Observable |
| 轮询对象的变化 | Observations { } |
NSLock、串行队列加锁 | Mutex |
withUnsafeBufferPointer | .span / RawSpan / OutputSpan |
热路径里固定大小的 Array | InlineArray<N, T> |
立即调用的闭包初始化 let、嵌套三元 | if / switch 表达式 |
| 手算字符串下标 | Swift Regex;日期、数字组合 Foundation 的解析器 |
XCTestCase + XCTAssert* | Swift Testing:@Test、#expect、try #require、@Test(arguments:) |
print | Logger;非数字插值默认脱敏,确定不涉隐私才 privacy: .public |
⚠ @available(anyAppleOS:)、mapKeyedValues、weak let、@diagnose、Task 取消屏蔽 | 工具链确认 6.4 后才用 |
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
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.

