adolfosrs
adolfosrs

Reputation: 9389

Querying for a pointer attribute using Parse

Im developing an app with User and Request as classes on Parse. My Users have currentLocation (PFGeoPoint) as an attribute and Requests have a pointer to refer the User that owns the request (requestor:PFUser). So Im trying to find requests from users near to the current user logged in.

I need to do something like:

let currentUserGeoPoint = PFUser.currentUser()!["currentLocation"] as! PFGeoPoint

var query = PFQuery(className:"Request")
query.whereKey("requestor.currentLocation", nearGeoPoint: currentUserGeoPoint)
query.findObjectsInBackgroundWithBlock {
      (objects, error) -> Void in
          if (error == nil) {
             self.userRequests = objects!
             self.tableView.reloadData()
          }else {
             println(error?.userInfo)
          }
}

But unfortunatelly this is not possible:

[Error]: Dot notation can only be used on objects (Code: 102, Version: 1.8.1)
Optional([code: 102, error: Dot notation can only be used on objects, temporary: 0, NSLocalizedDescription: Dot notation can only be used on objects])

Any ideas?

This is how my Request Class looks like on Parse:

enter image description here

This is the User Class:

enter image description here

Upvotes: 5

Views: 571

Answers (1)

the_critic
the_critic

Reputation: 12820

According to this question in the Parse Community:

Instead of dot notation in whereKey:, you would use whereKey:matchesKey:inQuery: or whereKey:matchesQuery:.

Upvotes: 8

Related Questions