Posts

Showing posts with the label decode

How to decode a base 64 string found in a JSON string to generate a UIImage

Image
Clash Royale CLAN TAG #URR8PPP How to decode a base 64 string found in a JSON string to generate a UIImage I have pasted my code below. Essentially, I have been given an SDK, which has a JSON string that I then have to parse in order to get to what is a base64 string from which a QR Code is generated. I have been working on it, but the code errors out at the "let nsd = ..." line, with the message: "Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value" Any help of where I am going wrong would be greatly appreciated. I am a novice when it comes to Swift and programming in general, so am finding this quite challenging. I am also don't think I am correctly converted the response into a JSON, as that is where it is first errorring out. func qrCodeGenerator(payload : String) { guard let response = /response as a string from SDK/ else {return} /* convert response string to an NSData response, so as to convert to JSON in the code belo...