一键导入
swift-actor-persistence
Swift actor-based data persistence patterns -- thread-safe storage using the actor model with in-memory caching and atomic file writes.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Swift actor-based data persistence patterns -- thread-safe storage using the actor model with in-memory caching and atomic file writes.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Regression testing strategies for AI-assisted development. Sandbox-mode API testing without database dependencies, automated bug-check workflows, and patterns to catch AI blind spots.
Clean Architecture patterns for Android and Kotlin Multiplatform projects -- module structure, dependency rules, UseCases, Repositories, and data layer patterns.
Performance baseline and regression detection -- page performance, API latency, build times, and before/after comparison.
Turn a one-line objective into a step-by-step construction plan for multi-session, multi-agent engineering projects. Each step has a self-contained context brief so a fresh agent can execute it cold.
Automated visual testing and interaction verification -- smoke tests, interaction tests, visual regression, and accessibility audits using browser automation.
Bun as runtime, package manager, bundler, and test runner. When to choose Bun vs Node, migration notes, and Vercel support.
| name | swift-actor-persistence |
| description | Swift actor-based data persistence patterns -- thread-safe storage using the actor model with in-memory caching and atomic file writes. |
| origin | ECC |
Thread-safe data storage in Swift using the actor model, which provides compile-time guarantees against data races.
@Observable view modelsThe pattern centers on an actor generic over Codable & Identifiable types that maintains an in-memory dictionary and persists to disk atomically:
actor DataRepository<T: Codable & Identifiable> where T.ID: Hashable & Codable {
private var items: [T.ID: T] = [:]
private let fileURL: URL
init(filename: String) {
let documents = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0]
self.fileURL = documents.appendingPathComponent(filename)
self.items = Self.loadFromDisk(url: fileURL)
}
func get(_ id: T.ID) -> T? {
items[id]
}
func getAll() -> [T] {
Array(items.values)
}
func save(_ item: T) {
items[item.id] = item
persistToDisk()
}
func delete(_ id: T.ID) {
items.removeValue(forKey: id)
persistToDisk()
}
private func persistToDisk() {
guard let data = try? JSONEncoder().encode(Array(items.values)) else { return }
try? data.write(to: fileURL, options: .atomic)
}
private static func loadFromDisk(url: URL) -> [T.ID: T] {
guard let data = try? Data(contentsOf: url),
let items = try? JSONDecoder().decode([T].self, from: data) else {
return [:]
}
return Dictionary(uniqueKeysWithValues: items.map { ($0.id, $0) })
}
}
@Observable
final class ItemListViewModel {
private(set) var items: [Item] = []
private let repository: DataRepository<Item>
init(repository: DataRepository<Item>) {
self.repository = repository
}
func load() async {
items = await repository.getAll()
}
func add(_ item: Item) async {
await repository.save(item)
await load()
}
}
Sendable