Last active
October 23, 2018 12:58
-
-
Save laevandus/28acb7f2c3a2728c2460271bf2cc8eb9 to your computer and use it in GitHub Desktop.
This file contains 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
extension PersistentDataStore { | |
func loadImage(forIdentifier identifier: Identifier, completionHandler block: @escaping (UIImage?) -> (Void)) { | |
loadData(forIdentifier: identifier, dataTransformer: { UIImage(data: $0) }, completionHandler: block) | |
} | |
func storeImage(_ image: UIImage, identifier: String = UUID().uuidString, completionHandler handler: @escaping (Result) -> ()) { | |
storeData({ image.jpegData(compressionQuality: 1.0) }, identifier: identifier, completionHandler: handler) | |
} | |
} | |
// Examples: | |
persistentStore.storeImage(image) { (result) in | |
print(result) | |
} | |
persistentStore.loadImage(forIdentifier: "my_identifier") { (image) -> (Void) in | |
guard let image = image else { | |
print("Failed loading image.") | |
return | |
} | |
print(image) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment