I have a chat filled with users and of course a username array. I want to get the profile picture associated with the username in order for each user in the username array. Parse, however, can only sort by ascending/descending order that I am aware of.
Therefore, I need to figure out how to sort the data once received. I am ultimately appending a url to be used as the pic.
func getPics(_ completionHandler: @escaping () -> Void) {
let query = PFQuery(className: "_User")
var dictionary: [String : Int] = [:]
var unit = 0
for username in usernameArray {
unit += 1
dictionary[username] = unit
}
query.findObjectsInBackground(block: { (objects: [PFObject]?, error: Error?) in
if let objects = objects {
for object in objects {
if error == nil {
for user in self.usernameArray {
let pfuser = object["username"] as! String
if pfuser == user {
let imageFile = object["profilePic"] as? PFFileObject
let imageFileString = imageFile?.url as! String
if let url = URL(string: imageFileString) {
let replacedImageUrlString = imageFileString.replacingOccurrences(of: "[removed for privacy]", with: "removed for privacy")
let url = replacedImageUrlString as NSString
self.urlArray.append(url)
}
}
}
}
}
completionHandler()
}
})
}