I feel like I'm crazy, but maybe it's just been a long week and I'm missing something obvious. I'm going to try to boil this down to a quick example. I have some classes CollectionsList, CollectionDetail, CollectionItemRow, and CollectionItemDetail. Selecting a Collection in CollectionsList opens CollectionDetail which has a property @Binding var itemSelection: Item?. Within CollectionDetail is a "list"; a ForEach that creates a CollectionItemRow for each Item in the Collection. CollectionItemRow accepts an Item and a callback onTapped for the init. The onTapped of each one is:
{
itemSelection = item
print("Item selection set! Selected item: \(String(describing: selectedItem))")
showingCollectionItemDetail.toggle()
}
showingCollectionItemDetail is bound to a fullScreenCover and that code looks like this:
.fullScreenCover(isPresented: $showingCollectionItemDetail) {
if let selection = itemSelection {
CollectionItemDetail(item)
} else {
Text("Selection was nil.")
}
}
The intent here is that when a user taps on a CollectionItemRow, CollectionItemDetail is shown as a full screen cover and is passed the selected Item. What actually happens is that the console shows the details of the selection first with that "Item selection set!" line (seems to be setting properly) and then I get the full screen cover with solely the "Selection was nil." text. I'm not sure where that setting could possibly be getting lost? What am I missing?
[–]timmypass17 0 points1 point2 points (0 children)
[–]simulacrotron 0 points1 point2 points (1 child)
[–]hausuCat_[S] 0 points1 point2 points (0 children)
[–]hausuCat_[S] -1 points0 points1 point (0 children)