Search code examples
iosxcodeswiftparse-platformpfquery

How to find PFUser with constraints?


I have tried to figure out how to find a PFUser with constraints, this is the only way I found. I don't know if I'm doing it wrong, but how would you display the results? When I try to display the results with println(query) it returns PFQuery surrounded by brackets (these <>) and it says PFQuery: and some random letters and numbers, I am most likely displaying it wrong that's why I'm wondering how to display it correctly. (Sorry I'm a newb)

let predicate = NSPredicate(format: "username = 'Ethan'")
var query = PFQuery(className: "_User", predicate: predicate)

Solution

  • You could use the whereKey method. And Parse also has a query specifically for the PFUser class.

        var query = PFUser.query()
        userQuery?.whereKey("username", equalTo: "Ethan")
    
        userQuery?.getFirstObjectInBackgroundWithBlock({ (result, error) -> Void in
            if let thisUser = result as? PFUser {
    
                println(thisUser.username)
    
            }
    
        })