HomeiOS Developmentios - The right way to name Job in NavigationLink vacation spot...

ios – The right way to name Job in NavigationLink vacation spot in SwiftUI?


I’ve created an inventory utilizing LazyVStack and within the checklist there are ListItemViews.

What I am making an attempt to do is, when a ListItemView will get tapped, I wish to make an async name relying on the chosen merchandise, after which navigate to the view with the information I fetched.

I’ve tried to take action by inserting a Job within vacation spot parameter of NavigationLink however I believe this isn’t permissible. I get Kind '() -> Job<some View, By no means>' can not conform to 'View' error.

Right here is the checklist that I am implementing

ScrollView {
    LazyVStack {
        ForEach(objects) { merchandise in
            NavigationLink(vacation spot: {
                Job {
                    await detailView(from: merchandise.id) // <- Kind '() -> Job<some View, By no means>' can not conform to 'View'
                }
            }, label: {
                ListItemView(merchandise: merchandise)
            })
            .padding(.horizontal, 8)
        } //: ForEach
    } //: LazyVStack
} //: ScrollView

And right here is the tactic that I take advantage of to generate vacation spot view.

non-public func detailView(from id: Int) async -> some View {
    guard let product = await viewModel.getProduct(with: id) else { return Textual content("Error").eraseToAnyView() }
    selectedProduct = product
    return ProductDetailView(product: $selectedProduct).eraseToAnyView()
}

Any concepts how can I implement this?

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments