Skip to content

Instantly share code, notes, and snippets.

@AlexFlyce
Created May 22, 2018 12:47
Show Gist options
  • Save AlexFlyce/69ba835634cc2bf6d8b7fd016bac4d1a to your computer and use it in GitHub Desktop.
Save AlexFlyce/69ba835634cc2bf6d8b7fd016bac4d1a to your computer and use it in GitHub Desktop.
ART001-AsyncImageView.swift
import UIKit
class AsyncImageView: UIView {
private var _image: UIImage?
var image: UIImage? {
get {
return _image
}
set {
_image = newValue
layer.contents = nil
guard let image = newValue else { return }
DispatchQueue.global(qos: .userInitiated).async {
DispatchQueue.main.sync { }
let decodedImage = UIImage.decodedImage(image)
DispatchQueue.main.async {
self.layer.contents = decodedImage?.cgImage
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment