I am using a REST API (https://restcountries.eu/) and want to download the flag image (which is an .svg) and show it as a UIImage
. I tried the standard way with:
func requestData(at url: URL, success: @escaping (_ data: Data) -> Void, failure: ((_ error: NetworkError) -> Void)? = nil) {
let request = URLRequest(url: url)
let task = URLSession.shared.dataTask(with: request) { (responseData, response, responseError) in
DispatchQueue.main.async {
if responseError != nil {
failure?(.failedRequest)
} else if let data = responseData {
success(data)
} else {
failure?(.corruptedData)
}
}
}
task.resume()
}
and the data downloads fine, but when I try to show the image with UIImage(data: data)
, the image is nil
. Am I missing something?