In my application, I'm attempting to instantiate a UIImage from Data. I've been seeing some crash logs come in from App Store Connect showing that my code is crashing on this particular line:
guard let data = photo.data, let image = UIImage(data: data) else { return nil }
Below is the backtrace. PhotoCache is the last object I have control over, and .imageFor(_:) is the method that the line above is contained in.
What is PFEvanscentData, and what might be causing it to crash in this scenario?
Edit: Here is the full method.
private var cache = NSCache<NSString, UIImage>()
func imageFor(_ photo: Photo) -> UIImage? {
guard let key = photo.id as NSString? else { return nil }
if let image = cache.object(forKey: key) {
return image
}
guard let data = photo.data, let image = UIImage(data: data) else { return nil }
cache.setObject(image, forKey: key)
return image
}
