Swift macros for resilient Codable — one unknown enum case or malformed array element no longer fails your whole response. Lenient by default, strict by explicit opt-in, with compile-time diagnostics and fix-its.
Highlights
@LenientDecodablegeneratesCodingKeys,init(from:), and theDecodableconformance for a struct, with every stored property lenient by default.@NilOnFailure(the implicit default) — any failure decodes asnilexactly where it broke: whole-value onT?, in-place element padding on[T?](count and positions preserved), and[T?]?for absent-vs-empty distinction.@DropOnFailure— failed array elements are removed, survivors keep their order. Never applied by default; dropping is an explicit product decision.@Strict— byte-for-byte synthesized decoding, and the only way a decode can fail.grep @Strictaudits every hard failure point.- Compile-time shape validation — invalid strategy/type combinations are compile errors with fix-its (
change 'Int' to 'Int?',add '@Strict', …), so nothing is silently strict and nothing is silently lenient. - Debug observability — every absorbed failure (including missing keys) logs via
os.Logger(subsystemLenientCodable, categorydecoding); JSONnullis the one intentional silent case. Logging compiles out entirely in release builds. - No wrapper types — properties stay plain stored properties, so
Equatable/Hashable/memberwise-init synthesis keep working, and the generated code is readable via Expand Macro.
Requirements
- Swift 6.2+ toolchain (Xcode 26+)
- iOS 13+, macOS 10.15+, tvOS 13+, watchOS 6+, Mac Catalyst 13+
Installation
dependencies: [
.package(url: "https://github.com/EngOmarElsayed/swift-lenient-codable.git", from: "1.0.0"),
]See the README for the full guide.