Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parse.com querying User class (swift)

I encounter some strange problem when I try to query all users from the "User" class It dos not find any Users

var query:PFQuery=PFQuery(className: "User");
    query.findObjectsInBackgroundWithBlock {
        (objects: [AnyObject]!, error: NSError!) -> Void in
        if !(error != nil) {
            for(var i=0;i<objects.count;i++){
                var object=objects[i] as PFObject;
                var name = object.objectForKey("username") as String;
                println(name);

            }
        }
    }

I tried replacing

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

with

var query:PFQuery=PFQuery(className: "AnotherClass");

and everything worked like i should. I think it must be something special about the "User" class

like image 609
tim_yng Avatar asked Oct 02 '14 20:10

tim_yng


2 Answers

User isn't the appropriate name for the User table. You need to use the following:

var query : PFQuery = PFQuery(className: "_User")

A more appropriate method is:

var query : PFQuery = PFUser.query()
like image 145
Dehli Avatar answered Nov 25 '22 11:11

Dehli


You cannot query users like that. Instead you need:

var findUsers:PFQuery = PFUser.query();
findUsers.whereKey("username",  equalTo: searchText.text)

See Parse documentation:

https://parse.com/docs/ios_guide#users-querying/iOS

like image 42
Tys Avatar answered Nov 25 '22 11:11

Tys