I created a preview using the new #Preview syntax for a View and I'm getting the error Amibiguous use of 'init(_:traits:body:)'
:
#Preview {
let viewModel = RecordingDetailViewModel(recording: nil, viewContext: PersistenceController.preview.container.viewContext)
TranscribingTransitionView(viewModel: viewModel)
}
I've tried a few things to resolve it, like adding return
as suggested here. Sometimes the error will go away when I build my project (and it always builds and runs on the simulator just fine), but as soon as I unpause the Preview, the error comes back.
I still get the error even when I switch back to the old syntax even though the error is showing up in an expansion of the macro that no longer exists:
struct TranscribingTransitionView_Previews: PreviewProvider {
static var previews: some View {
let viewModel = RecordingDetailViewModel(recording: nil, viewContext: PersistenceController.preview.container.viewContext)
TranscribingTransitionView(viewModel: viewModel)
}
}
Preview
code. Not a great answer to the problem, but it's possible thePreview
macro compliles differently to the actual build as it's live. My code worked fine in my app just as yours did. – Pounceyreturn
to the preview might also work: stackoverflow.com/questions/77000297 – Cave