stackerleet stackerleet - 3 years ago 148
Swift Question

I am trying to append PFGeoPoint from parse into array and convert into CLLocationCoordinate2D

I have multiple PFGeoPoints in parse an I want to import all of them, and append them to an array, so at the end it will be an array of geopoints i.e. [ [21,13], [45,67] ]. And I want to convert it to CLLocationCoordinate2D, but I get an error.
Error is

value of type [PFGeoPoint] has no member 'latitude'

var points: [[PFGeoPoint]] = [[PFGeoPoint]]()

if let coor = object["Point"] as? [PFGeoPoint]{

print("points \(self.points)")

for(var i = 0; i < self.points.count; i++){

let lonlat = CLLocationCoordinate2D(latitude: (self.points[i].latitude), longitude: (self.points[i].longitude)!)
print("lonlat \(self.coordinatelocation)")
if(self.coordinatelocation.count == self.points.count){



Answer Source

Your error message already gives you answer

value of type [PFGeoPoint] has no member 'latitude'

Your points is a variable with type [[PFGeoPoint]], a 2D array (array inside another array).

self.points[i] doesn't give you PFGeoPoint, it gives you a [PFGeoPoint].

What you need to do is self.points[i][something].latitude

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download