I have a SwiftUI app that includes a map with annotations and an overlay of polylines
on highways. I use Core Data to store Waypoint structs to configure the polylines.
Multiple Waypoints make a Trip.
The app is the basic Master/Detail style with a list of trips and a DetailView that
displays the map with the overlay. As a part of that process I calculate the time and
distance for each segment (between Waypoints). All of this works as expected with
one really strange problem.
When I start the app, the first Trip is displayed correctly with the correct time
and distance. However, when clicking on a second Trip the makeUIView function of the
UIViewRepresentable is called multiple times - even more strangely, five times. That
obviously wastes internet resources and it makes the time and distance incorrect. Now
if that is not strange enough, when clicking on a third Trip, the information is
correct. In fact, every other Trip is correct - it does not matter which is first,
every other is correct with the intervening ones all incorrect. My first thought was
that I had some strange toggle somewhere, but I do not. I cannot find anything that
should require the makeUIView to be called five times and certainly not every other time.
I have attached the
MapKitMakeUIViewQuestion.txt
code for the DetailView:
Just as an aside - I published this app to the App Store some time ago (and several
versions of iOS and Xcode ago) and I believe the app behaved as expected at that time.
Any guidance would be appreciated. Xcode 12.5 iOS 14.5