1

I'm programming in Swift and using Parse as my database. I'm trying to get an image from the database which is stored as a file. I downloaded it as a PFFile in an array in my code and naturally the imageView is thus unable to run the file because it's not a UIImage. I've seen people on stackoverflow asking but I don't really understand their explanation.

Array_

var photos:[PFFile] = []

PFObject_

let post = PFObject(className: "Items")

Retrieving_ where I don't know what to do

let imageFile:PFFile = (post as! PFObject) ["imageFile"] as! PFFile
rmaddy
  • 314,917
  • 42
  • 532
  • 579
James Lim
  • 83
  • 5
  • 1
    what are you really trying to do ? – Lamour Oct 16 '15 at 14:58
  • @Lamour agreed this is vague. As for the OP, check out the `PFImageView` included in the ParseUI framework. It automatically handles loading and updating a `UIImageView` – Russell Oct 16 '15 at 19:06

1 Answers1

0

You need to fetch the data from the PFFile and use that data to create the UIImage.

let postData = post.getData()
let image = UIImage(data: postData!)

The first lines is what retrieves the data from the PFFile that you received. The second line is what creates the UIImage from the data taken from the PFFile. Hopefully this explains the process a little better.

TheCodeComposer
  • 725
  • 5
  • 17