#Preview unable to see other generated Swift Macro code

I have recently created a very simple Swift Macro that I can attach to a view that will generate the boilerplate we have in the project for passing in the view model instance.

@TPView<CompanyProfileViewModel>
struct CompanyProfileView: View {
  ...
  // expanded code
  private (set) var viewModel: CompanyProfileViewModel
  init(viewModel: CompanyProfileViewModel) {
    self.viewModel = viewModel
  }
}

However the issue I'm running into is that whilst this init method is accessible in most of the project, when I try to use it in a #Preview block I get errors:

#Preview("Default") {
  CompanyProfileView(viewModel: .mock())
    .previewLayout(.fixed(width: 380, height: 2000))
}

Based on the top error it seems like the #Preview block isn't able to see the generated init method. I could go back to just using the standard preview code that doesn't using #Preview, but that seems like I'm taking a step forward and a step back with making the code less verbose.

Any suggestions on how to get this working? This seems like a bug to me.

in general, as a solution, you can add a global variable for your viewModel. but it doesn't look pretty

#Preview unable to see other generated Swift Macro code
 
 
Q