**Hi, hopefully you can help me with this swiftUI code? I have created a Map App which will show a route via a ManPolyLine (see the code).
Whilst I can print the route via the (in the code below) var _ = print("ROUTE = (route.steps.map { $0.instructions }.filter { !$0.isEmpty })")
I CANNOT create a variable for the route it prints? I need to do this so I can create a .sheet (which is shown), but cannot Access a Variable to List the route details!
Help would be most appreciated, TIA
(The pertinent part of the code below)**
===========================================
@State private var route: MKRoute?
@State private var myRoute: [String] = []
@State private var selectedResult: MKMapItem?
@State private var position: MapCameraPosition = .automatic
Map(position: $position, selection: $selectedResult)
{
ForEach(searchResults, id: \.self) {
result in
Marker(item: result)
}
.annotationTitles(.hidden)
UserAnnotation()
if let route {
MapPolyline(route)
.stroke(.blue, lineWidth: 5)
var myRoute = route.steps.map { $0.instructions }.filter { !$0.isEmpty }
var _ = print("ROUTE = \(route.steps.map { $0.instructions }.filter { !$0.isEmpty })")
var _ = print("COUNT = \(myRoute.count)")
}
}
===========================================
Out of interest, the line: var _ = print("ROUTE = (route.steps.map { $0.instructions }.filter { !$0.isEmpty })")
Produces the following output (source at Apple HQ), Destination nearby:
ROUTE = ["Turn right onto Infinite Loop", "Turn right onto Infinite Loop", "Turn right onto N De Anza Blvd", "Turn right onto Homestead Rd", "Turn right onto N Tantau Ave", "Turn left onto Forge Dr", "Arrive at the destination"]
But again, how do I “attach” the array to an Array variable to use later in the code?