Skip to content

2.0.0 Beta 2

Pre-release
Pre-release
Compare
Choose a tag to compare
@jrothwell jrothwell released this 02 Jan 02:09
· 22 commits to main since this release

Adds support for Swift Macros to VersionedCodable. You can now declare conformance to VersionedCodable like this:

@versionedCodable(v: 2, previously: PoemV1)
struct PoemV2 {
    var authorName: String?
    var authorDateOfBirth: Date?
    var authorDateOfDeath: Date?
    var poem: String
    
    init(from old: PreviousVersion) throws {
        self.authorName = old.author
        self.poem = old.poem
    }
}

Because macros are a new feature in the compiler, VersionedCodable 2.0 will require Swift 5.9.

This supersedes v2.0.0-beta.1, fixing a bug where nested types declared as PreviousVersion using the macro would only have their first token carried through to the resulting expansion (e.g. PreviousVersions.Version1 would be carried through as PreviousVersion, causing a compile error.) This was fixed by sending through the whole expression rather than just the first token.

As a side effect, the macro now does not use the usage of .self at the end of the previously parameter. This does look very weird, so a future enhancement would be to have compiler diagnostics help people stop doing this.