Declarative Codable conformance with Swift Macros
ETBCodable is a Swift Package that provides two Swift macros — @Codable and @CodingKey — to eliminate boilerplate when conforming your models to Codable. The macros generate a CodingKeys enum for your stored properties and attach Codable conformance, allowing the compiler to synthesize init(from:) and encode(to:) automatically.
- Zero runtime overhead: All code is generated at compile time.
- Non-invasive: If your type already conforms to
Codableor definesCodingKeys, the macro does nothing. - Fine-grained control: Override individual keys with
@CodingKey("custom_key"). - Safe defaults: Computed and
staticproperties are ignored.
- Swift 6.2 or later (the package uses
swift-tools-version: 6.2) - Platforms:
- macOS 10.15+
- iOS 13+
- tvOS 13+
- watchOS 6+
- macCatalyst 13+
- In Xcode, go to File > Add Package Dependencies…
- Enter the repository URL for this package:
https://github.com/elf0-fr/ETBCodable.git. - Add the
ETBCodableproduct to your target.
Add the package to your dependencies and link the ETBCodable product to your target:
// In your Package.swift
.dependencies: [
.package(url: "https://github.com/elf0-fr/ETBCodable.git", from: "1.0.0")
],
.targets: [
.target(
name: "YourTarget",
dependencies: [
.product(name: "ETBCodable", package: "ETBCodable")
]
)
]