I'm currently writing a social networking application in Swift. Inside my app I have feature that a user can send a message to the timeline with a image attached. I want to be able to retrieve the image and preview it using a UIImageView inside my timeline. However I want the image to display next to the user that sent the image and if a user did not post a image the image preview does not appear along with the message. A good example of the functionally I want to have is the way Facebook and Twitter display images in their respective iOS apps. in the meantime I have written the following function to retrieve the images, but i'm having trouble matching them up to the proper user. I will have my function posted below as well as link to download the source code to my timeline. Thanks in advance
func loadImages()
{
var query = PFQuery(className: "imagesUploaded")
query.orderByDescending("objectId")
query.whereKey("user", equalTo:PFUser.currentUser())
query.findObjectsInBackgroundWithBlock {
(objects:[AnyObject]!,error:NSError!) -> Void in
if error == nil {
let imagesobjects = objects as [PFObject]
for object : PFObject in objects as [PFObject] {
let image = object["filename"] as PFFile
image.getDataInBackgroundWithBlock {
(imageData:NSData!, error:NSError!) -> Void in
if error == nil {
if let finalimage = UIImage(data: imageData)
{
let url = image.url
println(url)
cell.imagedisplay.image = finalimage
}
}
}
}
}
}
}
I did this with this class :
Edit :
You can add a test like this :