Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chriswill0w/8bae5e2f62da78e7087a5fc3f1607890 to your computer and use it in GitHub Desktop.
Save chriswill0w/8bae5e2f62da78e7087a5fc3f1607890 to your computer and use it in GitHub Desktop.
UIImage that implements NSDiscardableContent
final class discardableThumbnail: NSDiscardableContent {
var thumbnail: UIImage!
var accessCounter: Int = 0
init(image: UIImage) {
thumbnail = image
}
func beginContentAccess() -> Bool {
if !(self.thumbnail != nil) {
return false
}
self.accessCounter += 1
return true
}
func endContentAccess() {
if self.accessCounter > 0 {
self.accessCounter -= 1
}
}
func discardContentIfPossible() {
if self.accessCounter == 0 {
self.thumbnail = nil
}
}
func isContentDiscarded() -> Bool {
return self.thumbnail == nil
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment