I am trying to add and image to a collectionView cell if a file associated with the cell is located on the device.
The file is there so the below code unhides the image, however i get an error that it found nil trying to unwrap optional.
any ideas whats wrong with the code?
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell: JourneyCollectionViewCell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath) as! JourneyCollectionViewCell
// query if file is on LDS and add image to indicate
let cellPartName = self.partArray[indexPath.item].name
let checkQuery = PFQuery(className: "downloadedAudio")
checkQuery.whereKeyExists(cellPartName)
checkQuery.fromLocalDatastore()
checkQuery.getFirstObjectInBackground(block: { (object, error) in
if error != nil || object == nil {
print("The file does not exist locally on the device, hide the image.")
//cell.ImageDownloaded.image = UIImage(named: "")
// crashes on this line
cell.ImageDownloaded.isHidden = true
} else {
print("the file already exists on the device, show the image.")
//cell.ImageDownloaded.image = UIImage(named: "download")
// crashes on this line
cell.ImageDownloaded.isHidden = false
}
})
return cell
}
the file already exists on the device, show the image.
fatal error: unexpectedly found nil while unwrapping an Optional value
(lldb)
image "download" is in the cassette.