Skip to content

Instantly share code, notes, and snippets.

@ShabanKamell
Created September 3, 2019 12:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ShabanKamell/11323d6e16c45325251466b311de22f8 to your computer and use it in GitHub Desktop.
Save ShabanKamell/11323d6e16c45325251466b311de22f8 to your computer and use it in GitHub Desktop.
// 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