How to convert an PFFile to an UIImage with swift?

后端 未结 3 1540
难免孤独
难免孤独 2020-12-04 00:43

How do i convert an PFFile to an UIImage with swift?

In this code, the app is getting the file from parse and now i want it to show on a UIImageView, But i get an er

3条回答
  •  悲&欢浪女
    2020-12-04 00:49

    PFFile is a parse representation of anykind of file. To get the "real" file (image), you need to call getDataInBackgroundWithBlock. Try it:

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

提交回复
热议问题