Last active
May 22, 2017 13:17
-
-
Save bennokress/33edb96cacca7ab89ca5cca6dc3948cd to your computer and use it in GitHub Desktop.
Swift Extensions to conveniently decode base64 into UIImage
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
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