I'm using MapKit
in my app and i needed drop pin an specific place and in another view controller, when will have an option to draw the route to that pin. So, i use this fantastic tutorial but i'm having trouble to pass the information with prepareForSegue
class Place: NSObject, MKAnnotation {
// This class creates the map annotation who have the place's location and some information about it
let title: String?
let locationName: String
let discipline: String
let coordinate: CLLocationCoordinate2D
// The title and the subtitle will appear when the user touches in a pin from a specific place.
init(title: String, locationName: String, discipline: String, coordinate: CLLocationCoordinate2D) {
self.title = title
self.locationName = locationName
self.discipline = discipline
self.coordinate = coordinate
super.init()
}
// The title will be the place's name and in the subtitle will appear where is the location
var subtitle: String? {
return locationName
}
}
So, in Map's ViewController, i has this func how works when the user taps a map annotation
pin if he taps this info button.
func mapView(mapView: MKMapView, annotationView view: MKAnnotationView,
calloutAccessoryControlTapped control: UIControl) {
let location = view.annotation as! Place
let launchOptions = [MKLaunchOptionsDirectionsModeKey: MKLaunchOptionsDirectionsModeDriving]
location.mapItem().openInMapsWithLaunchOptions(launchOptions)
}
So than i change this func
:
func mapView(mapView: MKMapView, annotationView view: MKAnnotationView,
calloutAccessoryControlTapped control: UIControl) {
let location = view.annotation as! Place
let launchOptions = [MKLaunchOptionsDirectionsModeKey: MKLaunchOptionsDirectionsModeDriving]
performSegueWithIdentifier("GoRestaurant", sender: self)
}
because like i sad, i wanna "openInMapsWithLaunchOptions" in another ViewController whos's identifier it's "GoRestaurant". So than i made a prepareForSegue
to send "location"and "launchOptions"
func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
var showPlace: RestaurantsViewController = segue.destinationViewController as! RestaurantsViewController
showPlace.location = location
showPlace.launchOptions = launchOptions
}
but, in the RestaurantsViewController
, when i try "import" location, don't works.
var locationName: String = "" //ok, no error
var location: Place = () //error: Cannot convert value of type '()' to specified type 'Place'
I try initialize so many times in so much different ways but i have no idea who fix it. Please, someone.. Save my life help me with this!