0

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?'

Basel
  • 550
  • 8
  • 21
  • It looks to me like the completion block you have written out doesn't match the expected `PFDataResultBlock` from the Parse framework. I haven't used Parse since they shut it down, but what do the Parse docs say? What's the expected syntax for a `PFDataResultBlock`. It seems weird to me to force unwrap `Data` and `Error`. Are you sure it's not supposed to be `(imageData: Data?, error: Error?) -> Void in`? – Pierce Jan 13 '17 at 22:08
  • also check the syntax for `PFDataResultBlock`. Has it been updated? It might need to use `NSData` instead of `Data` and `NSError` instead of `Error`. Just a thought. The only reason I say that is because, Parse was shut down like a year ago wasn't it? – Pierce Jan 13 '17 at 22:15
  • I'm sure about Data and Error instead of NSData and NSError because i have use it before and I got error when I use NSError. Parse has become Open Source , and now there is some alternative using Parse like Back4app.com – Basel Jan 13 '17 at 22:26
  • I think you just need to replace your exclamation points `!` with `?`. So say `getDataInBackgroundWithBlock({ (imageData: Data?, error: Error?) -> Void in .... )}` – Pierce Jan 13 '17 at 22:45
  • Thank you . I solve it , for some reason in Swift 3 `userPicture.getDataInBackgroundWithBlock` become `userPicture.getDataInBackground` and `NSData` = `Data` , `NSError` = `Error` – Basel Jan 13 '17 at 22:57
  • It just sounds like the Parse SDK has been updated to work with Swift 3. They've been working to cut out any unnecessary language and make function names more succinct – Pierce Jan 13 '17 at 23:00
  • You are right also `!` should be `?` I got error if I make it `!` – Basel Jan 13 '17 at 23:04

1 Answers1

2

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!)
 }
 })
}
Basel
  • 550
  • 8
  • 21