I’m trying to decode a base64 type to String, but the content is always nil.
There is how im getting the data from the json.
func downloadJSON (completed: @escaping () -> ()) {
let url = URL (string: "https://api.github.com/repos/\(details!.full_name)/readme")
URLSession.shared.dataTask(with: url!) { (data, response, error) in
if error == nil {
do {
print("ceva")
self.read = try JSONDecoder().decode(Readm.self, from: data!)
DispatchQueue.main.async {
completed()
}
} catch {
print (error)
}
}
}.resume()
}
Here is my func base64, I put a breakpoint at the return String, but the code is never executed , probably goes on the branch " return nil"
func base64Decoded(word: String) -> String? {
guard let base64Data = Data(base64Encoded: word) else { return nil}
return String(data: base64Data, encoding: .utf8)
}
This is how I’m doing the call
downloadJSON {
if let content = self.read?.content {
self.readMeLabel.text = self.base64Decoded(word: content)
}
}