I am trying to decode base64 String to
UIImage
in Swift 4.2. I have tried almost every solution on stackoverflow but it's not working.
I have tried converting the string
with NSData
, it didn't work. Now I am converting the string
to Data
and afterwards to image
but it's giving this error. (Type of expression is ambiguous without more context)
let encodedImageData = "gggg"
//let imageData = NSData(base64EncodedString: encodedImageData,
options: .)
//let imageData = NSData(base64Encoded: encodedImageData,
options: NSData.Base64DecodingOptions.ignoreUnknownCharacters)
//let image = UIImage(data:imageData)
//Trying to get this to work.
if let decodedData = Data(base64Encoded:encodedImageData,
options: .ignoreUnknownCharacters) {
let image = UIImage(data: decodedData)
}
It will be much appreciated, if anyone could point out what i am doing wrong. or give me solution. i have tried most of the solution anyways. Thank you