You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Thanks for making this macro. I'd like to use it unfortunately the generated initializer doesn't work inside the #Preview macro.
Example:
import SwiftUI
import MemberwiseInit
@MemberwiseInitstructTest{lettest:Int}structContentView:View{init(test:Test){}varbody:someView{EmptyView()}}
#Preview {ContentView(test:Test(test:1))// 🛑 'Test' cannot be constructed because it has no accessible initializers}
Checklist
If possible, I've reproduced the issue using the main branch of this package.
Thanks for the report! This seems to be a rather unfortunate upstream bug; feedback filed: FB13443736. I also reproduced this bug in the latest Xcode 15.1 beta 3 (15C5059c). I think the best we can do for now is fall back to the old PreviewProvider syntax:
If you inline the #Preview macro in your example using Xcode's "Refactor → Inline Macro" and strip the leading "$" from the generated name, it compiles as expected. That's not a workaround, tho: Xcode won't recognize it as a preview (and the expanded code is unpleasant).
Furthermore, this can be generalized to any closure argument given to a macro:
@MemberwiseInitpublicstructClosureTest{@Init(default:{Test(test:1)})letname:()->Test// ┬────────────// ╰─ 🛑 'Test' cannot be constructed because it has no accessible initializers}
The compiler is type-checking the closure argument without expanding macros first. This presents a complex situation where the dependency between macro expansion and type checking isn't properly resolved by the compiler.
Description
Thanks for making this macro. I'd like to use it unfortunately the generated initializer doesn't work inside the #Preview macro.
Example:
Checklist
main
branch of this package.Expected behavior
I've expected the code above to work.
Actual behavior
The code above doesn't compile: 'Test' cannot be constructed because it has no accessible initializers
Steps to reproduce
No response
swift-memberwise-init-macro version information
main
Destination operating system
macOS 14.1.1
Xcode version information
15.0 (15A240d)
Swift Compiler version information
The text was updated successfully, but these errors were encountered: