ios parse framework query on user

125 views Asked by At

I am trying to fetch some objects from the USER table in parse. I am absolutely sure that the username I am searching for is there but I even though I get a objects!.count == 0 when I do this:

    var query = PFQuery(className: "User") as PFQuery
    query.whereKey("username", equalTo: "myUsername")

    query.findObjectsInBackgroundWithBlock { (objects: [AnyObject]?, error: NSError?) -> Void in
        if error == nil {
            if objects!.count > 0{
                println("there are some objects like this!")
            } else {
                println("There are no objects like this!")
            }
        } else {

        }
    }

I have been trying the same with objectId but no luck I seriously don't know what to do with it .. it seems like something very easy.

1

There are 1 answers

1
Wain On BEST ANSWER

When querying for a user you can't use

var query = PFQuery(className: "User") as PFQuery

because the User class has a special name. Instead you need to use:

let query = PFUser.query()