ios – Bind Data in a sheet view


I debugged the code and apparently on the first tap the selectedNew variable comes nil but when I close the sheetView and tap on another card the selectedNew is populated with the correct information.

 ScrollView(.horizontal, showsIndicators: false) {
                        HStack(spacing: 20) {
                            ForEach(vm.latestNews.prefix(3)){card in
                                NewsCardView(title: card.attributes.title, date: card.attributes.publishingDate, thumbnail: baseURL+card.attributes.thumbMedia.data.attributes.formats.thumbnail.url)
                                    .onTapGesture {
                                        self.selectedNew = card
                                        self.showFullNew = true
                                    }
                            }
                        }
                        .sheet(isPresented: $showFullNew, onDismiss: {
                            self.selectedNew = nil
                        }) {
                            if let selectedNew = selectedNew {
                                FullNewsView(title: selectedNew.attributes.title, date: selectedNew.attributes.publishingDate, thumbnail: baseURL+selectedNew.attributes.thumbMedia.data.attributes.formats.thumbnail.url)
                                    .presentationDetents([.fraction(0.98)])
                            }
                        }
                        Spacer()
                    }.onAppear {
                        vm.fetchNewsFromAPI()
                    }

Latest articles

spot_imgspot_img

Related articles

Leave a reply

Please enter your comment!
Please enter your name here

spot_imgspot_img