Created
September 3, 2019 12:21
-
-
Save ShabanKamell/11323d6e16c45325251466b311de22f8 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
// show Base64 image in iOS | |
import UIKit | |
extension UIImageView { | |
func setImage( | |
base64: String?, | |
placeholder: UIImage? = nil | |
){ | |
guard base64 != nil else { | |
image = placeholder | |
return | |
} | |
let dataDecoded: Data? = Data( | |
base64Encoded: base64!, | |
options: Data.Base64DecodingOptions(rawValue: 0) | |
) | |
guard dataDecoded != nil else { | |
image = placeholder | |
return | |
} | |
image = UIImage(data: dataDecoded!) ?? placeholder | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment