Generate Entity Codable bridge from @Entity macro - #19
Merged
Merged
Conversation
Extends the macro to emit concrete init(from: ModelData) throws and encode() -> ModelData implementations for each @Attribute/@relationship property, using ModelData.decode/encode(forKey:) and decodeRelationship/encodeRelationship(forKey:) directly. This removes the need for the generic Codable-derived default implementation for any type using the macro.
Now generated by the @entity macro; the hand-written version duplicated the same behavior and would conflict with the macro-generated members.
Support code for the old Codable-based Entity bridge, which now lives in Tests/CoreModelTests/LegacyCodable.
Support code for the old Codable-based Entity bridge, which now lives in Tests/CoreModelTests/LegacyCodable.
No longer needed by the library now that the @entity macro generates encode() directly; kept in Tests/CoreModelTests/LegacyCodable and still exercised by CoreDataTests. Adds the CoreModel import the file now needs as a separate module.
No longer needed by the library now that the @entity macro generates init(from:) directly; kept in Tests/CoreModelTests/LegacyCodable and still exercised by CoreDataTests. Adds the CoreModel import the file now needs as a separate module.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
@Entitymacro to generate concreteinit(from: ModelData) throwsandencode() -> ModelDataimplementations for each@Attribute/@Relationshipproperty, callingModelData.decode/encode(forKey:)anddecodeRelationship/encodeRelationship(forKey:)directly — noSwift.Codableinvolved.Personinit/encode inTestModel.swift, now generated by the macro (it would otherwise conflict with the generated members).Encoder.swift,Decoder.swift, and theirCodingKey/CodingUserInfoKeysupport files) out ofSources/CoreModeland intoTests/CoreModelTests/LegacyCodable/. It's no longer part of the library's public surface, but stays exercised —CoreDataTestsstill calls its.encode(log:)/.init(from:userInfo:log:)overloads directly, while everything else now goes through the macro-generated zero-argencode()/init(from:).Test plan
swift test— 17/17 tests pass (both the macro-generated path and the relocated legacy bridge are exercised)swift build -c release— passesswift build --swift-sdk swift-6.3.2-RELEASE_wasm-embedded(macros disabled) — unaffected, still passes