Skip to content

Instantly share code, notes, and snippets.

@piyushdec
Created July 28, 2019 19:32
Show Gist options
  • Save piyushdec/d9d6d7c2d44dfaaae77fc3e785d91907 to your computer and use it in GitHub Desktop.
Save piyushdec/d9d6d7c2d44dfaaae77fc3e785d91907 to your computer and use it in GitHub Desktop.
class ImageDownloadHelper: SwiftOperation {
//1
let imageRecord: ImageRecord
//2
init(_ imageRecord: ImageRecord) {
self.imageRecord = imageRecord
}
//3
override func main() {
//4
if isCancelled {
return
}
//5
guard let imageData = try? Data(contentsOf: imageRecord.url) else { return }
//6
if isCancelled {
return
}
//7
if !imageData.isEmpty {
imageRecord.image = UIImage(data:imageData)
imageRecord.state = .downloaded
} else {
imageRecord.state = .failed
imageRecord.image = UIImage(named: "Failed")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment