MetaCodable: SwiftData class: Method does not override any method from its superclass
If a SwiftData model annotation is added to a class, the build will fail with “Method does not override any method from its superclass”.
It can be reproduced using a clean SwiftData project, adding the SPM package from 1.2.1, and the following class:
import Foundation
import SwiftData
import MetaCodable
import HelperCoders
protocol MyProtocol {
}
@Codable
@Model
final class Item : MyProtocol {
@CodedAt("timestamp")
var timestamp: Date? = nil
init() { }
}
Expanding the macro actually shows it doesn’t add the super.* calls:
I have however managed to produce one expansion with the error:
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 3
- Comments: 16 (7 by maintainers)
@ashleydw @Willian-Zhang new macro
Inheritshas been added (only inmainbranch, not released yet) to workaround the issue until this is fixed from compiler.@soumyamahunt I can confirm it works in my project, thanks!
@rursache you have to remove the manual
Codableconformance you are adding, due to this addition compiler is also generatingCodableimplementation which is conflicting with this library’s generated implementation.having Inherits tested, I can confirm this solved my problem perfectly.
@soumyamahunt great insight! @soumyamahunt @ashleydw Are you available to fire a bug report or discussion as you said to apple by any chance? I don’t think I’m qualified enough for this as I’m new to SwiftLang let alone any insight on how swift macro works.
If not, do you think there is way to go around with this problem? I am very interested in this cross usage on SwiftData+MetaCodable, as it would vastly simplify my code in a project that I started recently. (Actually I’m current on a track giving up on
#Previewcapability just to have this working)Thanks @ashleydw for providing sample, I can reproduce your issue. The issue doesn’t seem to be combining
@Codablewith SwiftData class, in fact the project builds successfully if you comment out following lines:https://github.com/ashleydw/metacodable-min-ex/blob/c0bd383995ca3c12938f704b79429e2c9c7b0c9b/test/ContentView.swift#L6 https://github.com/ashleydw/metacodable-min-ex/blob/c0bd383995ca3c12938f704b79429e2c9c7b0c9b/test/ContentView.swift#L11-L18 https://github.com/ashleydw/metacodable-min-ex/blob/c0bd383995ca3c12938f704b79429e2c9c7b0c9b/test/ContentView.swift#L50 https://github.com/ashleydw/metacodable-min-ex/blob/c0bd383995ca3c12938f704b79429e2c9c7b0c9b/test/ContentView.swift#L58
Seems like with these line present Swift is not providing protocol conformance data to
@Codable. It would be better if you create a discussion on Swift forum or Apple developer forum as the issue doesn’t seem to beMetaCodablerelated.Here’s a repo: https://github.com/ashleydw/metacodable-min-ex/blob/main/test/Item.swift
If you build you should get the same error on Item.swift. Commenting out
@CodableandCodedAtshould build successfully and run.