I have very little knowledge on data passes and need help on how to pass a LocalSearchResponse that has already populated a mapview to then use a UIButton to segue to a tableview to have those pin annotations to be listed.
matchingItems.removeAll()
let request = MKLocalSearchRequest()
request.naturalLanguageQuery = shopType
request.region = mapView.region
let search = MKLocalSearch(request: request)
search.start(completionHandler: {(response, error) in
if error != nil {
print("Error occured in search: \(error!.localizedDescription)")
} else if response!.mapItems.count == 0 {
print("No matches found")
} else {
print("Matches found")
for item in response!.mapItems {
print("Name = \(String(describing: item.name))")
print("Phone = \(String(describing: item.phoneNumber))")
self.matchingItems.append(item as MKMapItem)
print("Matching items = \(self.matchingItems.count)")
let annotation = MKPointAnnotation()
annotation.coordinate = item.placemark.coordinate
annotation.title = item.name
self.mapView.addAnnotation(annotation)
self.listedButton.isEnabled = true
}
}
})
I want to list the places searched with the Name, and Phone in a tableview.