1

Hi guys I'm trying to print my query which Ive created in Parse, here it is this works fine and does what i need it to

 //store my currentLocations here
var locations : [PFObject] = []    

PFGeoPoint.geoPointForCurrentLocationInBackground { (geoPoint: 
PFGeoPoint?, error: NSError?) -> Void in

        if geoPoint != nil {

            var geoPointLon = geoPoint?.longitude
            var geoPonitLan = geoPoint?.latitude
            var currentLocation = PFGeoPoint(latitude: geoPonitLan!, longitude: geoPointLon!)

            var query = PFQuery(className: "User")
            query.whereKey("currentLocation", nearGeoPoint: currentLocation, withinKilometers: 5.0)
            query.findObjectsInBackgroundWithBlock({ (objects: [AnyObject]?, error: NSError?) -> Void in

                if let myObject = objects as? [PFObject] {

                    for objects in myObject {

                        self.locations.append(objects)

                    }

                }

                self.tableView.reloadData()


            })

        }

    }

this is my tableview cell and number of rows

 func tableView(tableView: UITableView, numberOfRowsInSection section: 
 Int) -> Int {

    return self.locations.count


}

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

    let cell = UITableViewCell()

    cell.textLabel?.text = "test"

    return cell

}

when running my app "test" does print the correct number of entries so I know my query is working.

My question is how can I print the actual locations from my class "User", column named "currentLocation" within Parse?

if you need any other info just let me know thanks

2
  • You are creating your cell wrongly. Commented Aug 22, 2015 at 9:04
  • hey yep I know, this is a test cell to print the number of queries, need the correct version to display whats in the database Commented Aug 22, 2015 at 9:13

1 Answer 1

1

Assuming your "currentLocation" column is a string, that's how you get it back.

if it is not a string, then you might need to convert it.

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

    let cell = UITableViewCell()

    cell.textLabel?.text = self.locations["currentLocation"]

    return cell

}
Sign up to request clarification or add additional context in comments.

1 Comment

trying to convert via as? String but getting an error, this column is a PFObject and contain geoPoint locations, any thoughts?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.