$npx skillfedfor your agent

swift-actor-persistence

Swift Actor Persistence demonstrates how to construct a thread-safe persistence layer by combining actor isolation with hybrid storage—keeping frequently accessed data in memory while syncing changes to disk. The pattern leverages Swift's compile-time guarantees to prevent data races without manual locks, making it ideal for offline-first applications and shared mutable state across concurrent contexts.

Swift Actor Persistence enables you to build thread-safe data storage using Swift actors combined with memory caching and file persistence.

AI-generated summary based on this skill's SKILL.md

1,767 298 MITupdated by xu-xiang

Decision gist · record as of 2026-03-05

Swift Actor Persistence enables you to build thread-safe data storage using Swift actors combined with memory caching and file persistence. Swift Actor Persistence demonstrates how to construct a thread-safe persistence layer by combining actor isolation with hybrid storage—keeping frequently accessed data in memory while syncing changes to disk. The pattern leverages Swift's compile-time guarantees to prevent data races without manual locks, making it ideal for offline-first applications and shared mutable state across concurrent contexts.

manual: git clone https://github.com/xu-xiang/everything-claude-code-zh → cp -r everything-claude-code-zh/skills/swift-actor-persistence ~/.claude/skills/swift-actor-persistence
skills/swift-actor-persistence/SKILL.md · version fabf8043

Use it when

  • Swift Actor Persistence eliminates the need for DispatchQueue and manual locking by using actor-based serialization.
  • Yes.

Verify before relying

Read SKILL.md below before installing (1 file). Open directory: indexed for reading, not audited.

Same gist for agents: .md · .json

Install

xu-xiang/everything-claude-code-zh/swift-actor-persistence · repository language: JavaScript

Open directory. Skills are indexed for reading, not audited. Review a skill's body before installing it.

Frequently asked questions

AI-generated answers based on this skill's SKILL.md and metadata

What is swift actor thread safe persistence?

Swift Actor Persistence is a pattern that uses Swift actors to build thread-safe data storage without manual locks. It combines in-memory caching with file-based persistence, ensuring safe concurrent access through actor isolation. The approach leverages Swift's compile-time concurrency guarantees to prevent data races in shared mutable state, making it ideal for offline-first applications.

How does Swift Actor Persistence replace locks and DispatchQueue?

Swift Actor Persistence eliminates the need for DispatchQueue and manual locking by using actor-based serialization. Actors automatically serialize access to their mutable state, guaranteeing that only one task can execute at a time. This removes the complexity of managing locks while providing stronger compile-time safety guarantees than traditional concurrency patterns.

Can I combine memory caching with file-based persistence safely?

Yes. Swift Actor Persistence demonstrates hybrid storage by keeping frequently accessed data in memory while syncing changes to disk. The actor model ensures that both cache and file operations remain synchronized and thread-safe. This pattern is particularly effective for offline-first apps where local data must be reliably persisted and quickly accessible.

What is the swift actor based repository pattern?

Swift Actor Persistence implements a repository pattern where an actor manages all data access—both reading from and writing to storage. The actor isolates mutable state, handles serialized file I/O, and coordinates between memory cache and persistent storage. This centralizes concurrency concerns and eliminates data races across your application.

How does Swift Actor Persistence eliminate data races?

Swift Actor Persistence prevents data races through actor isolation and Sendable constraints. Actors serialize all access to shared mutable state, ensuring only one concurrent task modifies data at a time. Combined with Swift's type-safe Sendable protocol for data crossing actor boundaries, the pattern provides compile-time guarantees that eliminate race conditions.

Is Swift Actor Persistence suitable for offline-first apps?

Yes. Swift Actor Persistence is designed for offline-first applications by providing reliable local storage with thread-safe concurrent access. The hybrid memory-and-file approach ensures data persists across app sessions while remaining quickly accessible. The actor model guarantees safe concurrent reads and writes, essential for apps that must work reliably without network connectivity.

SKILL.md

Rendered from the published skill. Quoted content, verbatim.

使用 Swift Actors 实现线程安全持久化 (Swift Actors for Thread-Safe Persistence)

使用 Swift actor 构建线程安全数据持久化层的模式。该模式结合了内存缓存(In-memory caching)与基于文件的存储,利用 actor 模型(Actor model)在编译时消除数据竞争(Data races)。

何时启用

  • 在 Swift 5.5+ 中构建数据持久化层
  • 需要对共享可变状态(Shared mutable state)进行线程安全访问
  • 希望消除手动同步操作(如 locks、DispatchQueues)
  • 构建具有本地存储的离线优先(Offline-first)应用

核心模式 (Core Pattern)

基于 Actor 的仓库模式 (Actor-Based Repository)

Actor 模型保证了序列化访问(Serialized access)—— 由编译器强制执行,确保不会出现数据竞争。

```swift public actor LocalRepository<T: Codable & Identifiable> where T.ID == String { private var cache: [String: T] = [:] private let fileURL: URL

public init(directory: URL = .documentsDirectory, filename: String = "data.json") {
    self.fileURL = directory.appendingPathComponent(filename)
    // 在 init 期间同步加载(此时 actor 隔离尚未生效)
    self.cache = Self.loadSynchronously(from: fileURL)
}

// MARK: - 公共 API

public func save(_ item: T) throws {
    cache[item.id] = item
    try persistToFile()
}

public func delete(_ id: String) throws {
    cache[id]

(truncated - see the full file via the links below)

File tree — 1 file
skills/swift-actor-persistence/SKILL.md

Let your AI agent find skills like this

Example. Real query, live index.

You found this page by searching. An agent finds it by wishing: SkillFed indexes 56,283 agent skills by what they can do, searchable in plain language.

wish › “Implement thread-safe data persistence using Swift actors”

Give your agent the search over MCP, or paste the wish link into any chat. No install? Search from any chat →

Related skills

swift-code-review
by existential-birds · existential-birds/beagle

This skill systematically audits Swift source files for concurrency hazards, including unsafe async/await patterns, actor reentrancy, Sendable conformance gaps, and memory leaks from retain cycles. It establishes Swift language version context upfront, reads full enclosing symbols rather than diffs alone, and applies targeted checklists for error handling, force unwraps, and closure capture semantics before reporting findings.

Apache-2.0updated Jul 2026
★ 74repo stars
Swift Language
by dpearson2699 · dpearson2699/swift-ios-skills

Swift Language covers contemporary syntax and idioms for core Swift development, excluding concurrency and SwiftUI. Learn if/switch expressions, typed throws, result builders, property wrappers, opaque versus existential types, guard patterns, the Never type, regex builders, Codable techniques, modern collection methods, FormatStyle basics, and string interpolation. Routes specialized topics like deep decoding, formatting, API naming, concurrency, and SwiftUI state to dedicated skills.

no license declared → metadata onlyupdated Jul 2026
★ 932repo stars
Swift Codable
by dpearson2699 · dpearson2699/swift-ios-skills

Swift Codable teaches you to serialize and deserialize Swift types to and from JSON using the standard Codable protocol. Learn automatic synthesis, custom key mapping, nested container navigation, date and data strategies, and integration patterns with URLSession, SwiftData, and UserDefaults.

no license declared → metadata onlyupdated Jul 2026
★ 932repo stars
swift-concurrency-6-2
by xu-xiang · xu-xiang/everything-claude-code-zh

This skill guides you through Swift 6.2's concurrency paradigm, where code runs single-threaded by default and background work requires explicit @concurrent annotation. Learn how async functions now stay on the caller's actor, eliminating implicit thread offloading that caused data races in earlier versions. Master isolated protocol conformances for MainActor types and adopt MainActor inference to reduce boilerplate in app targets.

MITdocs in Chineseupdated Mar 2026
★ 1,767repo stars
swift
by miles990 · miles990/claude-software-skills

Swift is a powerful, modern programming language designed for building iOS, macOS, and other Apple platform applications. This skill covers core language concepts, syntax patterns, and contemporary best practices to help you write efficient, type-safe code. Whether you're starting fresh or deepening your expertise, you'll gain practical knowledge for real-world development scenarios.

MITupdated Jan 2026
★ 19repo stars
Swiftdata
by dpearson2699 · dpearson2699/swift-ios-skills

Swiftdata is a skill that enables agent integration with Swiftdata services. Use this skill to connect your agent to Swiftdata and unlock data handling capabilities within your workflows.

no license declared → metadata onlyupdated Jul 2026
★ 932repo stars

More skills swift-rules (Apache-2.0) · swift-concurrency-6-2 (MIT) · modernize-tests (MIT)

Tags
concurrent-safetyactor-modellocal-storagememory-cachingoffline-firstsendable-typesfile-persistenceswift-concurrencydata-race-eliminationrepository-pattern