#Preview macro breaks the PreviewTests.generated file
ynnckcmprnl opened this issue ยท 3 comments
Context ๐ต๏ธโโ๏ธ
I'm integrating Prefire 2.1.1 in a SwiftUI Design System package.
What ๐ฑ
The #Preview macro causes the PreviewTests.generated
file to contain compile errors. It seems that in some cases the #Preview macro breaks the generated code.
Error: Expected '(' in argument list of function declaration
.
When I remove the #Preview macro and create the SwiftUI preview with the old method, the compiler will fail on another one of these errors, but for a different preview. It seems like Prefires parsing of the #Preview macro is incorrectly adding a curly brace to the name in the generated code.
Example #Preview:
#Preview {
VStack {
Redacted("Hello, World!", .style1, .color1)
}
}
The generated code in PreviewTests.generated
, note the VStack{
reference in the name.
func test_VStack{_Preview() {
let preview = {
VStack {
Redacted("Hello, World!", .style1, .color1)
}
}
if let failure = assertSnapshots(matching: AnyView(preview()), name: "VStack{", isScreen: true, device: deviceConfig) {
XCTFail(failure)
}
}
Thanks for starting the issue!
As a quick fix, I can suggest adding a name to the #Preview
.
For example:
#Preview("Redacted") {
VStack {
Redacted("Hello, World!", .style1, .color1)
}
}
PS: I am currently making a Pull Request with a fix)
Thanks! This resolves the curly brace issue.
Although I've ran into another problem: #49