swift-actor-persistence
在 Swift 中使用 actor 实现线程安全的数据持久化——基于内存缓存与文件支持的存储,通过设计消除数据竞争。
Content Preview
---
name: swift-actor-persistence
description: 在 Swift 中使用 actor 实现线程安全的数据持久化——基于内存缓存与文件支持的存储,通过设计消除数据竞争。
origin: ECC
---
# 用于线程安全持久化的 Swift Actor
使用 Swift actor 构建线程安全数据持久化层的模式。结合内存缓存与文件支持的存储,利用 actor 模型在编译时消除数据竞争。
## 何时激活
* 在 Swift 5.5+ 中构建数据持久化层
* 需要对共享可变状态进行线程安全访问
* 希望消除手动同步(锁、DispatchQueue)
* 构建具有本地存储的离线优先应用
## 核心模式
### 基于 Actor 的存储库
Actor 模型保证了序列化访问 —— 没有数据竞争,由编译器强制执行。
```swift
public actor LocalRepository<T: Codable & Identifiable> where T.ID == String {
private var cache: [StHow to Use
Recommended: Install to project (local)
mkdir -p .claude/skills
curl -o .claude/skills/swift-actor-persistence.md \
https://raw.githubusercontent.com/affaan-m/everything-claude-code/main/docs/zh-CN/skills/swift-actor-persistence/SKILL.mdSkill is scoped to this project only. Add .claude/skills/ to your .gitignoreif you don't want to commit it.
Alternative: Clone full repo
git clone https://github.com/affaan-m/everything-claude-codeThen reference at docs/zh-CN/skills/swift-actor-persistence/SKILL.md
Related Skills
swift-concurrency-6-2
Swift 6.2 可接近的并发性 — 默认单线程,@concurrent 用于显式后台卸载,隔离一致性用于主 actor 类型。
swift-concurrency-6-2swiftconcurrency
by affaan-m · everything-claude-code
swift-protocol-di-testing
基于协议的依赖注入,用于可测试的Swift代码——使用聚焦协议和Swift Testing模拟文件系统、网络和外部API。
swift-protocol-di-testingswiftprotocoltesting
by affaan-m · everything-claude-code
swift-expert
Builds iOS/macOS/watchOS/tvOS applications, implements SwiftUI views and state management, designs protocol-oriented architectures, handles async/await concurrency, implements actors for thread safety, and debugs Swift-specific issues. Use when building iOS/macOS applications with Swift 5.9+, SwiftUI, or async/await concurrency. Invoke for protocol-oriented programming, SwiftUI state management, actors, server-side Swift, UIKit integration, Combine, or Vapor.
swift-expertswiftexpert
by Jeffallan · jeffallan-claude-skills
swift-macos-expert
Use proactively for Swift and macOS desktop application development, debugging, testing, and architecture. Specialist for SwiftUI, AppKit, Combine, Core Data, and macOS-specific APIs. Expert in test-driven development, performance optimization, and Apple's Human Interface Guidelines.
agentsswiftmacosexpert
by qdhenry · claude-command-suite