lundi 23 mars 2015

Swift Image retrieving from Parse sdk

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. I wrote the following function but I'm receiving a "unexpected found nil while unwrapping a Optional Value" error. I'm hoping somebody in the community can point out what I'm doing wrong.



func loadImages()
{
var query = PFQuery(className: "imagesUploaded")
query.orderByDescending("objectID")

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 {
let finalimage = UIImage(data: imageData)
self.timelineImages.append(finalimage!)
self.timelineimage.image = finalimage?
}
}
}
}
}
}



Aucun commentaire:

Enregistrer un commentaire