senty senty - 7 months ago 14
Swift Question

Decoding base64String value returns nil

I am trying to get an UIImage from base64String but I am facing an interesting problem. Even though the encoded string is full, decoding it returns nil.

let base64String = imageFilePath as! String
print(base64String) // returns encoded value

let decodedData = NSData(base64EncodedString: base64String, options: NSDataBase64DecodingOptions(rawValue: 0))
print(decodedData) // returns nil


Edit: It goes like


24wKiOQeetKPWmsx3AjtQMe+cDApoOTinCTOOKUsF5osIbtK800E5yKRySeeKFf ZQA5m79KkjYHr1qMupHWkbJGVoGTE0majXceT0qQkAUCGEUo5GKYOT81S5AOKEND
WUg0wg9BUu4dKibAOKYCAHFKOCCaQ9cGkBzQApbk5o3D7p/A0mRS9e1AD1BPSnCN
RzQnA5pjHPFMdhWcgbVHFSggr0/

Answer

You can try this code:

let decodedData = NSData(base64EncodedString: base64String, options:NSDataBase64DecodingOptions.IgnoreUnknownCharacters)

Comments