Install any skill in seconds. Free to start, no credit card required.
Get Started Free →xu-xiang/swift-actor-persistence
Swift 中使用 actor 实现的线程安全数据持久化 —— 结合内存缓存与文件存储,从设计上消除数据竞争。
Passed 20 of 22 test cases with the skill, and 16 of 22 without it.
and 4 more in the full report
5 fixed15 passed either way1 still failing1 broke
Tokens, turns and time describe resource use, not a dollar price.
One of 5 test cases the skill fixed. Same model, same prompt, with and without the skill.
编写 Swift 本地 Actor 存储库的构造函数 `init` 时,针对 `directory` 参数应该提供什么合理的默认系统目录 URL?请写出包含默认参数值的 `init` 函数头。
| Checked | Without skill | With skill |
|---|---|---|
| Uses URL documentsDirectory as the default directory parameter value. | Missed | Passed |
The instructions your model reads when the skill loads.
使用 Swift actor 构建线程安全数据持久化层的模式。该模式结合了内存缓存(In-memory caching)与基于文件的存储,利用 actor 模型(Actor model)在编译时消除数据竞争(Data races)。
Actor 模型保证了序列化访问(Serialized access)—— 由编译器强制执行,确保不会出现数据竞争。
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] = nil
try persistToFile()
}
test cases passed, vs 16 / 22 without
Published skills whose descriptions closely match this one, with their headline benchmark lift.
More skills from the same source and nearby in the registry, with their headline benchmark lift.