Skip to content

Instantly share code, notes, and snippets.

@mminer
Last active May 21, 2021 15:00
Show Gist options
  • Save mminer/7e1eea352e7dbab322b90d64f5f362cc to your computer and use it in GitHub Desktop.
Save mminer/7e1eea352e7dbab322b90d64f5f362cc to your computer and use it in GitHub Desktop.
NSImage extension that allows initializing an image from a Base64 encoded string.
import AppKit
extension NSImage {
convenience init?(base64EncodedString: String) {
guard
let url = URL(string: base64EncodedString),
let data = try? Data(contentsOf: url)
else {
return nil
}
self.init(data: data)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment