IOS - extracting and displaying an image from Parse in UIImageView (Swift 1.2 bug)

I previously retrieved the image form containing my Parse inside for display in my application inside the UIImageView using the following lines of code:

let userPicture = PFUser.currentUser()["picture"] as PFFile

userPicture.getDataInBackgroundWithBlock { (imageData:NSData, error:NSError) -> Void in
    if (error == nil) {

            self.dpImage.image = UIImage(data:imageData)

    }
}

But I get the error:

'AnyObject? not converted to "PFFile"; you wanted to use how! force downcast?

"Useful" Apple hint fix-it tells how! change, so I add in !, but then I get the error:

'AnyObject? does not convert to 'PFFile'

In the 'getDataInBackgroundWithBlock' section, I also get the error message:

It is not possible to call 'getDataInBackgroundWithBlock' using an argument list of type '((NSData, NSError) -> Void)'

- , Parse UIImageView Swift 1.2?

+4
1

PFUser.currentUser() (Self?). .

PFUser.currentUser()?["picture"]

, , . , , , .

if let userPicture = PFUser.currentUser()?["picture"] as? PFFile {

getDataInBackgroundWithBlock() (NSData? NSError?). , NSData NSError.

userPicture.getDataInBackgroundWithBlock { (imageData: NSData?, error: NSError?) -> Void in

, , :

if let userPicture = PFUser.currentUser()?["picture"] as? PFFile {
    userPicture.getDataInBackgroundWithBlock { (imageData: NSData?, error: NSError?) -> Void in
        if (error == nil) {
            self.dpImage.image = UIImage(data:imageData)
        }
    }
}
+10

All Articles