Parse.com request Custom class (fast)

I'm having some kind of weird problem when I try to request all users from the User class. He does not find 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 to replace

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

with

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

and everything worked as it should. I think this should be something special in the User class

+6
source share
4 answers

User is not a suitable name for the User table. You need to use the following:

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

More suitable method:

 var query : PFQuery = PFUser.query() 
+21
source

You cannot request such users. Instead, you need to:

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

See analysis documentation:

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

+5
source

I am also stuck in this part of the code. I was able to query users and their data using this code:

  var usernames = [String]() var userImages = [Data]() var query : PFQuery = PFUser.query()! // Interested in locations near user. query.whereKey("location", nearGeoPoint: geopoint!) // Limit what could be a lot of points. query.limit = 10 do { let queryObjects = try query.findObjects() for object in queryObjects { self.usernames.append(object["username"] as! String) self.userImages.append(object["image"] as! Data) } } catch { print("Error") } 
0
source

try it...

  var ObjectIDQuery = PFQuery (className: "User") ObjectIDQuery.findObjectsInBackgroundWithBlock({ (objectsArray : [AnyObject]?, error: NSError?) -> Void in var objectIDs = objectsArray as! [PFObject] NSLog("\(objectIDs)") for i in 0...objectIDs.count-1{ self.NameArray.append(objectIDs[i].valueForKey("username")as! String) self.iDArry.append(objectIDs[i].valueForKey("objectId") as! String) self.tableView.reloadData() 
-1
source

Source: https://habr.com/ru/post/976175/


All Articles