Skip to content

Instantly share code, notes, and snippets.

@svanimpe
Last active October 19, 2021 23:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save svanimpe/152e6539cd371a9ae0cfee42b374d7c4 to your computer and use it in GitHub Desktop.
Save svanimpe/152e6539cd371a9ae0cfee42b374d7c4 to your computer and use it in GitHub Desktop.
SwiftUI ObjectBinding in a UIViewRepresentable
struct LotMapWrapperView: View {
@EnvironmentObject var store: ParkingStore
var body: some View {
LotMapView(store: store)
}
}
struct LotMapView: UIViewRepresentable {
@ObjectBinding var store: ParkingStore
func makeUIView(context: UIViewRepresentableContext<LotMapView>) -> MKMapView {
MKMapView()
}
func updateUIView(_ view: MKMapView, context: UIViewRepresentableContext<LotMapView>) {
// This is not getting called when store sends didChange :(
print("Update view")
print(store.parkingLots.count)
}
}
@dan-ryan
Copy link

I have had great issues trying to get updateUIView to call on binding changes on iOS14. The class RandomClass { } let x = RandomClass() hack works perfectly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment