Skip to content

Instantly share code, notes, and snippets.

@bennokress
Last active May 22, 2017 13:17
Show Gist options
  • Save bennokress/33edb96cacca7ab89ca5cca6dc3948cd to your computer and use it in GitHub Desktop.
Save bennokress/33edb96cacca7ab89ca5cca6dc3948cd to your computer and use it in GitHub Desktop.
Swift Extensions to conveniently decode base64 into UIImage
import UIKit
extension String {
var image: UIImage? { return UIImage(from: self) }
}
extension UIImage {
convenience init?(from base64string: String) {
guard let imageData = Data(base64Encoded: base64string, options:.ignoreUnknownCharacters) else {
return nil
}
self.init(data: imageData)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment