swiftparse-platformpfqueryparse-ios-sdk

PFQuery returning blank query


I'm trying to run a PFQuery that will populate an array of custom structs.

Everything looks ok, but when I run the code the query returned is empty. I also tried this using PFUser.Query, which worked, but did not return a value for objectId, so tried to query the class instead.

Here is what I have:

var parseUsers:[ParseUsers] = []
var allUsers:[PFObject] = []
let query = PFQuery(className:"User")
let currentUser = PFUser.current()
query.whereKey("username", notEqualTo: currentUser?.username)
do {
    allUsers = try (query.findObjects())
    for i in allUsers{
        var pImage = UIImage()
        if i["profileImage"] != nil{
            let imageFile = i["profileImage"] as? PFFileObject
            imageFile?.getDataInBackground { (imageData: Data?, error: Error?) in
                if let error = error {
                    print(error.localizedDescription)
                } else if let imageData = imageData {
                    pImage = UIImage(data:imageData)!
                }
        }

        }

       let currentUserInfo = ParseUsers(objectID:i["objectId"] as! String,
                           username:i["objectId"] as! String,
                           userWorkouts:i["userWorkouts"] as! [Dictionary<String, String>],
                           profileImage:pImage)
        parseUsers.append(currentUserInfo)


    }
} catch {
    print("Error")
}

Solution

  • Found out what the problem was!

    For anyone experiencing similar issues in the future, when determining the class you want to query, you need to out _ in front. In the case above it would be let query = PFQuery(className:"_User").

    Weird, as I couldn't see this mentioned in the parse documentation anywhere.