I'm trying to save the coordinates of a user while in one ViewController so that it can be used to create an Annotation that can displayed in another ViewController.
In the view controller that stores the coordinates I'm using the code
NSUserDefaults.standardUserDefaults().setObject( Location, forKey: "Location")
In the map view controller that displays the annotation I'm trying to get the coordinates using the code
let Location = NSUserDefaults.standardUserDefaults().stringForKey("Location")
var Annotation = MKPointAnnotation()
Annotation.coordinate = Location
It is telling me that the value of type String?
to a value of type CLLocationCoordinate2D
.
So how do I convert the CLLocationCoordinate2D
coordinates into a value of type String
?
This way you can store Locations to
NSUserDefaults
:After that you can access it this way:
UPDATE:
HERE is your Example project.