boppa boppa - 2 months ago 13
iOS Question

Unable to retrieve User data from Parse database with query

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!

JVS JVS
Answer
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.

Comments