I'm using Parse for my app written in Swift. It is a golf app that allows the user to have a profile. The user can edit the profile on an edit profile view controller, save it and then they're taken back to the main profile view controller. The problem I'm having is if the user changes their profile image and saves it, the image isn't updated on the main profile view controller but the rest of the new profile info is. My belief is the timing is off with the Parse query and the image isn't coming back in time. Here is my query for my main profile page. I tried using the "dispatch_async" method but this doesn't seem to be working. Thanks in advance.
func getProfileFromBackground() {
profileData.removeAll()
if let userQuery = PFUser.query() {
userQuery.whereKey("username", equalTo: (PFUser.currentUser()?.username)!)
userQuery.findObjectsInBackgroundWithBlock({ (currentUserProfile:[PFObject]?, error: NSError?) -> Void in
if error == nil {
for object:PFObject in currentUserProfile! {
self.profileData.append(object)
for data in self.profileData {
dispatch_async(dispatch_get_main_queue()) {
self.golferNameLabel.text = data.objectForKey("name") as? String
self.usernameLabel.text = "Username: \(data.objectForKey("username")!)" as String
self.golferProfileImage.file = data.objectForKey("profileImage") as? PFFile
self.golferProfileImage.loadInBackground()
}
}
}
} else {
print(error)
}
})
}
}