0
votes

I'm trying to pull locations near a user via Parse for tableview, except I only get either a white screen or an empty table.

Edited: I neglected to add the call for location before query near geopoint is submitted. In testing, I found that location was determined under 'geoPontForCurrentLocationInBackground'. However, once the geopoint is established and the query is submitted, the user location returns no latitude or longitude within the query. Moreover, the query doesn't return any objects and I'm not sure why:

override func queryForTable() -> PFQuery! {
    var query = PFQuery(className: "User")

     PFGeoPoint.geoPointForCurrentLocationInBackground {
        (userLocation: PFGeoPoint!, error: NSError!) -> Void in
        if error == nil {

        }
    }

    let point: PFGeoPoint = PFGeoPoint(latitude: self.userLoc.latitude, longitude: self.userLoc.longitude)
    query.whereKey("location", nearGeoPoint: point, withinMiles: 50.0)
    query.limit = 10
    return query
    }

override func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!, object: PFObject!) -> PFTableViewCell! {
    let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as Shops
    if let object = object {
        if let shopName = object.valueForKey("shopName") as? String {
        cell.shopList.text = shopName
   }
   }
    return cell as Shops
 }
2

2 Answers

0
votes

You are setting up the query, but never actually executing it. Per the Parse documents, you need to add:

// Final list of objects
queryResults = query.findObjects()

Before your queryForTable() return statement in order to get the query objects.

0
votes

I believe the issue is that Parse treats the User class as a special class. You may have difficulty querying User class if you treat it as if it was a Custom Class.

The correct and tested way to do this is to the the query function of PFUser.

var query = PFUser.query()