Post

Replies

Boosts

Views

Activity

Reply to SwiftUI MapKit - MapAnnotation - Publishing changes from within view updates is not allowed, this will cause undefined behavior.
Check Map's initializer called when you move Map's region. This is simple example class PlaceViewModel: ObservableObject {     var region: MKCoordinateRegion = .seoul     @Published var places: [Place] = [] } struct PlaceView: View {     @StateObject var viewModel = PlaceViewModel()     var body: some View {         ZStack(alignment: .top) {             Map(                 coordinateRegion: $viewModel.region,                 annotationItems: viewModel.places             ) { item in                 MapAnnotation(coordinate: item.location) {                     Text(item.title)                 }             }         }     } }
Mar ’23