SwiftUI MapAnnotation Publishing changes warnings

Hello,

I am facing SwiftUI runtime warnings while implementing MapAnnotation [SwiftUI] Publishing changes from within view updates is not allowed, this will cause undefined behavior., there are new warnings when the map is moved.

Implementing MapMarker instead of MapAnnotation solves the problem. What am I doing wrong with MapAnnotation?

The code is running on Xcode version 14.1 (14B47b) and Simulator Version 14.1 (986.5)

struct AnnotationItem: Identifiable {
    let id = UUID()
    var coordinate: CLLocationCoordinate2D
}

struct MapView: View {
    @Binding var region: MKCoordinateRegion
    @Binding var items: [AnnotationItem]

    var body: some View {
        Map(coordinateRegion: $region, 
            annotationItems: items) { item in
            MapAnnotation(coordinate: item.coordinate) {
                Image(systemName: "cup.and.saucer.fill")
            }
        }
    }
}
Post not yet marked as solved Up vote post of emmanuel22 Down vote post of emmanuel22
1.6k views

Replies

i'm currently into this as well.. using MapMarker works but i can't figure out a way to make it tappable like in MapAnnotation

  • MapAnnotation seems to be broken at the moment in version Xcode 14.1 I am experiencing this problem too. Any idea how we can try to fix this?

Add a Comment