I have a problem when trying to user ternary operator on a button in NavigationLink. I have an array of campaigns, which is displayed in a carouselView. Bellow carousel there is
This is because the types of CampaignDetailsView
and Text
don't match. You need to use a @ViewBuilder
(or just a Group
, VStack
etc).
Here is a solution with the destination view as a @ViewBuilder
computed property:
@ViewBuilder
var destinationView: some View {
if cardCampaigns.count > 0 {
CampaignDetailsView(viewModel: CampaignDetailsViewModel(campaign: cardCampaigns[self.count].campaign))
} else {
Text("No Campaign found")
}
}
Which you can use like this:
NavigationLink(destination: destinationView) { ... }