0

I'm unable to retrieve any user data from the parse database with two query methods. I can get all currentUser data quite easily; however, can't seem to successfully retrieve data from other users. I have a feeling it's quite a simple fix that I'm looking over but I've tinkered with my code for a while now and still returning nil for each variable.

First query method:

let userQuery = PFQuery(className: "User")
       userQuery.whereKey("username", equalTo: username)
   userQuery.findObjectsInBackgroundWithBlock { (users, error) -> Void in
      if error == nil {
        if let objects = users {
            for object in objects {
                if let user = object as? PFUser {

                    self.userBio = user.objectForKey("bio") as! String
                    if user.objectForKey("icon") != nil {
                        self.userIcon = user.objectForKey("icon") as! PFFile
                    }
                    if user.objectForKey("header") != nil {
                    self.headerFile = user.objectForKey("header") as! PFFile
                    }
            }
        }
    }
    }
}

Second query method:

let userQuery = PFUser.query()
       userQuery?.whereKey("username", equalTo: username)
   userQuery!.findObjectsInBackgroundWithBlock { (users, error) -> Void in
      if error == nil {
        if let objects = users {
            for object in objects {
                if let user = object as? PFUser {

                    self.userBio = user.objectForKey("bio") as! String
                    if user.objectForKey("icon") != nil {
                        self.userIcon = user.objectForKey("icon") as! PFFile
                    }
                    if user.objectForKey("header") != nil {
                    self.headerFile = user.objectForKey("header") as! PFFile
                    }
            }
        }
    }
    }
}

Thanks in advance for any help!

3
  • I think it might be because the security of the User class is set differently by default... You have to change, you can do it in the parse dashboard Commented Sep 11, 2016 at 11:29
  • @JVS got it to work using "_User"! Thanks man Commented Sep 12, 2016 at 5:27
  • I will put my comment as an answer under your post. If you like, please accept it. Commented Sep 12, 2016 at 10:39

1 Answer 1

1
let userQuery = PFQuery(className: "User")

needs to be changed into

let userQuery = PFQuery(className: "_User")

since the user class of Parse.com is a special class. and it's name is by default spelled with an underscore.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.