Skip to content

Instantly share code, notes, and snippets.

@nalexn
Created December 7, 2019 20:43
Show Gist options
  • Save nalexn/5f18718c52cae1f821b25d1347751af6 to your computer and use it in GitHub Desktop.
Save nalexn/5f18718c52cae1f821b25d1347751af6 to your computer and use it in GitHub Desktop.
struct ContentView: View {
@State var selectedAnnotation: MKAnnotationID?
@State var annotations: [MKAnnotation] = []
var body: some View {
ZStack {
MapView(selected: self.$selectedAnnotation, annotations: self.$annotations)
ForEach(self.annotations) { annotation in
NavigationLink(
destination: AnnotationDetailsView(annotation: annotation),
tag: annotation.id,
selection: self.$selectedAnnotation) {
EmptyView()
})
}
}
}
}
struct MapView: UIViewRepresentable {
let selected: Binding<MKAnnotation.ID>
let annotations: Binding<[MKAnnotation]>
...
func didSelectAnnotation(annotation: MKAnnotation) {
self.selected.wrappedValue = annotation.id
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment