0

I am new to Swift and I am trying to find the current user location, and then query all nearby users and then load them into a UITableView in my storyboard. However, when I build my code, no data shows in my UITableView (Parse is my backend). I tried to research the problem and found this way of using PFQueryTableViewController:

PFQueryTableViewController in swift not loading data

However, when I do this

required init(coder aDecoder: NSCoder) {
    super.init(coder: aDecoder)
  }

always returns an NSException error. How can I fix that problem or fix the below code to return my parse data into my table view?

import UIKit
import Parse
import ParseUI
import CoreLocation

class MasterTableViewController: PFQueryTableViewController {

var usersLocation: PFGeoPoint? {
    didSet {
        // This will reload the tableview when you set the users location.
        // Handy if you want to keep updating it.
        if (tableView != nil) {
            tableView.reloadData()
        }
    }
}

override func viewDidLoad() {
    super.viewDidLoad()

    PFGeoPoint.geoPointForCurrentLocationInBackground { point, error in
        if error == nil {
            self.usersLocation = point
        }
    }

}

override func queryForTable() -> PFQuery {
    var query = PFQuery(className: "User")
    if let location = usersLocation {
        query.whereKey("location", nearGeoPoint: location)
    }
    query.limit = 10
    return query
}
Community
  • 1
  • 1

1 Answers1

0

In your queryForTable method it seems you're trying to query the User class.

From Parse docs, to query for users there is a special way of doing it:

example:

var query = PFUser.query()

query.whereKey("gender", equalTo:"female")

var girls = query.findObjects()

https://www.parse.com/docs/ios/guide#users-querying

Hopefully that helps

Simon
  • 6,413
  • 6
  • 34
  • 57
  • I don't know the syntax off the top of my head but, try checking to see if the current user exists first by using `var user = PFUser.currentUser()`. Then, if that goes through then you query the user, or else display the error. – Simon May 21 '15 at 21:36
  • If the user exists, and query is successful then trying reloading the tableview in the viewDidLoad method by calling `self.reloadData()` Also make sure in your storyboard under the identity inspector in the utilities tab your Custom Class name is connected to the MasterTableViewController since that is where the data is from. – Simon May 22 '15 at 02:39