This was pretty simple all that needed to be done was to change the data representation to use UIImagePNGRepresentation(_:)
instead of UIImageJPEGRepresentation(_:_:)
. The change is made in the setImage
(_:forKey:)` method.
ImageStore.swift - before
class ImageStore {
...
func setImage(_ image: UIImage, forKey key: String) {
cache.setObject(image, forKey: key as NSString)
let url = imageURL(forKey: key)
if let data = UIImageJPEGRepresentation(image, 0.5) {
let _ = try? data.write(to: url, options: [.atomic])
}
}
...
}
ImageStore.swift - after
class ImageStore {
...
func setImage(_ image: UIImage, forKey key: String) {
cache.setObject(image, forKey: key as NSString)
let url = imageURL(forKey: key)
if let data = UIImagePNGRepresentation(image) {
let _ = try? data.write(to: url, options: [.atomic])
}
}
...
}