Im trying to convert a base64 string to an UIImage
First. I decode the String as shown below
let decodedData = NSData(base64Encoded: decodeIMG, options: NSData.Base64DecodingOptions(rawValue: 0))
Then I try to convert the decoded data to an UIImage like this:
let decodedIamge = UIImage(data: decodedData as Data)
But on that line I get the following error:
Cannot convert value of type 'NSData?' to type 'Data' in coercion
I already tried using another approach to convert it by using an extension that looks like this
extension String {
//: ### Base64 encoding a string
func base64Encoded() -> String? {
if let data = self.data(using: .utf8) {
return data.base64EncodedString()
}
return nil
}
//: ### Base64 decoding a string
func base64Decoded() -> String? {
if let data = Data(base64Encoded: self) {
return String(data: data, encoding: .utf8)
}
return nil
}
}
And get this error
Incorrect argument label in call (have 'base64Encoded:', expected 'map:')