agentleFS
xu-xiangxu-xiang/everything-claude-code-zh/.cursor/rules/swift-patterns.md

everything-claude-code-zh / rules

Cursor rule2k starsChanged 9 months agoMITView on GitHub

扩展通用规则的 Swift 模式

Trending

More talk lately.thin dataabout the whole repository

Dec 2025: 0 mentionsJan 2026: 0 mentionsFeb 2026: 0 mentionsMar 2026: 0 mentionsApr 2026: 0 mentionsMay 2026: 0 mentionsJun 2026: 0 mentionsJul 2026: 0 mentionsAug 2026: 0 mentionsSep 2026: 0 mentionsOct 2026: 1 mentionNov 2026: 0 mentions
Dec 2025Jun 2026Nov 2026
Mentions a month of the xu-xiang/everything-claude-code-zh repository that our weekly crawl found: only 1 in all, so this is a hint, not a trend. There is no adoption data for this file yet.

Who's talking about xu-xiang/everything-claude-code-zh

The biggest 1 of 1 mention linking to the repository that our crawl found. Each line is their own headline.

The file

Files
swift-patterns.md

Swift 模式(Swift Patterns)

本文件扩展了通用模式规则,增加了 Swift 特有的内容。

面向协议设计(Protocol-Oriented Design)

定义小而集中的协议(protocols)。使用协议扩展(protocol extensions)来提供共享的默认值:

protocol Repository: Sendable {
    associatedtype Item: Identifiable & Sendable
    func find(by id: Item.ID) async throws -> Item?
    func save(_ item: Item) async throws
}

值类型(Value Types)

  • 使用结构体(structs)作为数据传输对象和模型
  • 使用带有关联值(associated values)的枚举(enums)来建模不同的状态:
enum LoadState<T: Sendable>: Sendable {
    case idle
    case loading
    case loaded(T)
    case failed(Error)
}

Actor 模式(Actor Pattern)

使用 Actor 来处理共享的可变状态,而不是使用锁(locks)或调度队列(dispatch queues):

actor Cache<Key: Hashable & Sendable, Value: Sendable> {
    private var storage: [Key: Value] = [:]

    func get(_ key: Key) -> Value? { storage[key] }
    func set(_ key: Key, value: Value) { storage[key] = value }
}

依赖注入(Dependency Injection)

通过默认参数注入协议——生产环境使用默认值,测试环境注入 Mock 对象:

struct UserService {
    private let repository: any UserRepository

    init(repository: any UserRepository = DefaultUserRepository()) {
        self.repository = repository
    }
}

参考资料(References)

参考技能:swift-actor-persistence 了解基于 Actor 的持久化模式。 参考技能:swift-protocol-di-testing 了解基于协议的依赖注入(DI)和测试。

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.