You simply create an instance of ShopDetailViewController by setting a value and then doing nothing with it. The instance of ShopDetailViewController that you created goes out of scope and freed.
How do you represent ShopDetailViewController ? Do you use segue? If you are then you must override the prepareForSegue() method, where you will get an instance of ShopDetailViewController that will be presented, and not go out of scope, and then just set the shopNameData property shopNameData .
EDIT:
Thanks for explaining how you represent the view controller. Therefore, to answer your comment:
You need to go to FirstVC and add something like the following code:
override func prepare(for segue: UIStoryboardSegue, sender: Any?) { if let viewController = segue.destination as? ShopDetailViewController, let annotationView = sender as? MKAnnotationView, let annotation = annotationView.annotation as? POIAnnotations { viewController.shopNameData = annotation.title } }
Then after that you can simply delete the code in your func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) method func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) and save the code in the func mapView(_ mapView: MKMapView, annotationView view: MKAnnotationView, calloutAccessoryControlTapped control: UIControl) method func mapView(_ mapView: MKMapView, annotationView view: MKAnnotationView, calloutAccessoryControlTapped control: UIControl) .
This way you simply call the present and pass the MKAnnotationView through the sender, and then take out the relevant information when the segue prepares to present your view controller. Hope this makes sense.
source share