Я не могу получить результаты от Pixabay API. Я перепробовал все, но не вижу ошибки, когда печать возвращает ноль.
Это мой код Swift:
import SwiftUI
struct dataImg : Codable{
let total: Int
let hits : [hitsImages]
struct hitsImages: Codable {
let fullHDURL : String
let downloads : Int
}
}
/*
struct PixaImage : Decodable {
let total : Int
let totalHits: Int
let hits : [hitsImages]
}*/
let apiKey = "****"
/*I've got the api in my swift but i don't wanna make it public :P*/
let urlParam = "&image_type=photo&orientation=vertical&lang=es"
let url = URL(string: "https://pixabay.com/api/?key=\(apiKey)")
URLSession.shared.dataTask(with: url!) { (data, _, _) in
if let data = data {
let imagesdecoder = try? JSONDecoder().decode(dataImg.self, from: data)
//Declaramos la url de la api y ejecutamos para ver que conecta -> corecta correctamente
print(imagesdecoder?.total)
}
}.resume()
Результат print(imagesdecoder?.total)
равен нулю, но данные мне что-то дают как 15000 байтов информации. Здесь вы можете увидеть пример API Pixabay