Reputation: 1647
I currently have a PFGeoPoint on a Parse Server which I can successfully retrieve by doing the following (in Swift):
let geo = listingObject?.objectForKey("geo")
// <PFGeoPoint: 0x7ff37d184840, latitude: 51.510005, longitude: -0.128493>
What I am now wanting to do is get the latitude and longitude out of this into their own variables.
When I create a map annotation for example the following works:
let anno = mapAnnotation(coordinate: CLLocationCoordinate2D(latitude: (geo?.latitude)!, longitude: (geo?.longitude)!))
However this produces an error:
let latitude = geo?.latitude
// Ambiguous use of 'latitude'
Can anyone point me in right direction?
Upvotes: 0
Views: 76
Reputation: 285200
objectForKey
returns AnyObject
, the compiler doesn't know that the type is PFGeoPoint
. The solution is to cast the value to the proper type.
And when using optional bindings you can get rid of all ?!
marks
if let geo = listingObject?.objectForKey("geo") as? PFGeoPoint {
let anno = mapAnnotation(coordinate: CLLocationCoordinate2D(latitude: geo.latitude, longitude: geo.longitude)
}
Upvotes: 2