2

I have an class in Parse which has been put into an array, like this :

 // PFQuery to get all Events
        var GetAllEvents : PFQuery = PFQuery(className: "Types_")
        GetAllEvents.findObjectsInBackgroundWithBlock{
            (objects:[AnyObject]!, error:NSError!) ->Void in

            if (error == nil) {
                for object in objects {
                    self.EventData.addObject(object)
                    println(object)


                self.tableView.reloadData()
            }
            }else
            {
                println("Error \(error)")
            }
        }

I am trying to put the results into a tableview, and this is fine with the strings , but with the image I am really struggling.

 cell.EventTitle.text = (event.objectForKey("Title") as String!)
        cell.EventType.text = (event.objectForKey("TypeOfVenue_") as String!)

        var image = UIImage(data: (event.objectForKey("TypeImage"))! as NSData)

So when i try and create an variable for the image - it just crashes, any ideas ?

Jason
  • 1,057
  • 3
  • 13
  • 31
  • See my answer here : http://stackoverflow.com/questions/27595220/downloading-pffile-image-from-parse-append-it-to-array-and-fill-uiimageview-wi/27596932#27596932 – soulshined Jan 03 '15 at 12:02

1 Answers1

3

PFFile can't be casted to NSData, what you need to do is to use it method getData to retrieve NSData:

let file = event["TypeImage"]
file.getDataInBackgroundWithBlock({ (data, error) -> Void in
   if let data = data where error == nil{
   var image = UIImage(data: data)
}
})
Shmidt
  • 16,436
  • 18
  • 88
  • 136