1

Considering I'm using PFImageViews, with caching enabled, I would like to know if there's a way to determine whether an image has already been downloaded or not.

All in all, I want to say:

if imageAlreadyDownloaded {
    ...
}
else {
    ...
}

Is it possible?

Sotiris Kaniras
  • 520
  • 1
  • 12
  • 30
  • If you are planning to use it , please read before starting to implement it. shutdown by Jan 28, 2017. http://blog.parse.com/announcements/moving-on/.. – NNikN Nov 20 '16 at 00:30
  • @andyPaul Thank you, but I knew that... I forgot to mention, I have my own Parse Server.. ;-) – Sotiris Kaniras Nov 20 '16 at 12:04

2 Answers2

1

So, I finally found the solution to my own problem! Every PFFile, has a boolean property called "isDataAvailable".

With a bit of code we can have the following solution:

let imageFile = file as? PFFile

if imageFile.isDataAvailable {
    ...
}
else {
    ...
}

And done! ;-)

Sotiris Kaniras
  • 520
  • 1
  • 12
  • 30
0

I think you will have to roll your own solution using the PFImageView and the loadInBackground method that has a completion handler.

Something like:

// Instance property on your UIViewController
private var imageAlreadyDownloaded = false

// Somewhere else in your UIViewController...
imageView.loadInBackground() { 
    [unowned self] (image, error) in

    guard error == nil else {
        return
    }
    self.imageAlreadyDownloaded = true
}
Ryan H.
  • 2,543
  • 1
  • 15
  • 24
  • In that case, I think the image would be downloaded in both cases, which I want to prevent.. Right? – Sotiris Kaniras Nov 20 '16 at 12:07
  • My intention was that this code would be called once, when you initiate your download. I did not intend for `loadInTheBackground` to be called twice. That said, it seems you found another good solution. – Ryan H. Nov 21 '16 at 01:57