Search code examples
swiftparse-platformback4app

PFFile to UIImage with swift 3?


I'm trying to use this code

if let userPicture = object.valueForKey("Image")! as! PFFile {
   userPicture.getDataInBackgroundWithBlock({
      (imageData: Data!, error: Error!) -> Void in
         if (error == nil) {
            let image = UIImage(data:imageData)
            self.ImageArray.append(image)
         }
      })
}

I got this error

Cannot convert value of type '(Data!, Error!) -> Void' to expected argument type 'PFDataResultBlock?'


Solution

  • I Solved my problem

    Swift 3 :

    if let userPicture = object.valueForKey("Image")! as! PFFile {
    userPicture.getDataInBackground({ (imageData: Data?, error: Error?) -> Void in
    let image = UIImage(data: imageData!)
    if image != nil {
    self.imageArray.append(image!)
     }
     })
    }