Created
February 18, 2017 22:14
-
-
Save benbahrenburg/e7567dc3ff0470e1296d1027469f0b03 to your computer and use it in GitHub Desktop.
UIImage that implements NSDiscardableContent
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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