Rule Swift

Protocol Extensions

Use protocol extensions for default implementations instead of base classes

swiftprotocolsarchitecturemacosios
CLAUDE.md

Prefer protocols with default implementations over base class inheritance. Protocol extensions provide shared behavior without coupling.

protocol Loadable {
    var isLoading: Bool { get set }
    func startLoading()
    func stopLoading()
}

extension Loadable {
    func startLoading() { /* default spinner logic */ }
    func stopLoading() { /* default cleanup */ }
}

Use protocol composition (Loadable & Cacheable) to combine capabilities without multiple inheritance problems.

Copy this block into your CLAUDE.md or agent config file to enforce it in your workflow.

get crystl