Closed rursache closed 7 months ago
Unfortunately, I don't think this is possible to fix within MemberwiseInit. Further, it may not even be addressable within the design of Swift Macros: by design, @Model
can't "see" the members added by @MemberwiseInit
.
As it stands, adding a manual initializer seems the only viable workaround. You might try raising the issue with Apple, which would need to be sent using Feedback Assistant.
For completeness, the @Model
macro's implementation is inspecting the syntax of the class, and emitting an error when that syntax doesn't include an initializer:
@Model
┬─────
╰─ 🛑 @Model requires an initializer be provided for 'Test'
@MemberwiseInit class Test {
var works: String?
}
(Reordering the macros here or in general has no effect.)
@gohanlon thanks for the long and detailed answer, I really appreciate it! i'm nee to macros and SwiftData, hoped to get rid of the lengthy boilerplate inits
Description
Checklist
main
branch of this package.Expected behavior
Test(works: "Yes!")
should workActual behavior
Test(works: "Yes!")
outputs error@Model requires an initializer be provided for 'Test'
swift-memberwise-init-macro version information
0.3.0 /
main
branchDestination operating system
macOS 14.4.1 (23E224)
Xcode version information
Xcode 15.3 (15E204a)
Swift Compiler version information