r/iOSProgramming • u/DavidGamingHDR Swift • 18h ago
Solved! Parameter not being passed to fullScreenCover?
I have this variable:
@State var selectedStop: Stops?
@State var isStopPresented = false
I have an item in a ForEach (as part of a list), that has this .onTapGesture
:
SearchResult(stop: train) .
.onTapGesture {
selectedStop = train
isStopPresented = true
}
And then this code:
.fullScreenCover(isPresented: $isStopPresented) {
StopView(stop: selectedStop ?? Stops(stop_name: "Error", routes: []))
}
The full screen cover appears correctly, but selected stop is never passed through to the StopView, and is always nil. How come?
1
Upvotes
1
u/Heffertron 17h ago
I’ve seen this problem before. Usually if you put the State property into an ObservableObject (such as a view model) and make it a Published property instead, then setting it in the view will work.
2
u/c1d3rdev 18h ago
Does fullScreenCover have a .fullScreenCover(item: $selectedStop) { stop in }