Post

Replies

Boosts

Views

Activity

UIViewRepresentable.updateUIView(_:context:) is not called when @State, @Binding or @EnvironmentObject are changed.
I have a GameView that has "@State var locationManager: LocationManager" which is passed to my MapView as a binding. The MapView conforms to UIViewRepresentable protocol. LocationManager conforms, among other things, to ObservableObject and has the following conformance-related code:var didChange = PassthroughSubject<locationmanager, never="">() var lastKnownLocation: CLLocation { didSet { // Propagate the update to the observers. didChange.send(self) print("Finished propagating lastKnownLocation to the observers.") } }I suppose that GameView and consequently MapView must be updated every time LocationManager.lastKnownLocation changes. In practice I only see MapView.updateUIView() called when I exit the app per home button. At this point control gets in updateUIView() and when I open the app again (not compile-install-run), I get the update. This also happens once short after the GameView() was presented.Is my understanding of how SwiftUI works wrong or is it some bug? How do I get it right?
10
0
1.0.0k
Oct ’19