简体   繁体   中英

ios parse framework query on user

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.

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()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM