struct JSONData: Decodable {
var data: [APIResponse]?
}
struct APIResponse: Codable {
var title: String?
var created_at: String?
}
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let jsonUrlString = "https://api.github.com/repos/Alamofire/Alamofire/issues"
guard let url = URL(string: jsonUrlString) else { return }
URLSession.shared.dataTask(with: url) { (data, response, err) in
guard let data = data else{ return }
do {
let courses = try JSONDecoder().decode(JSONData.self, from: data)
print(courses.data as Any)
} catch let jsonErr {
print("Error serializing json:", jsonErr)
}
}.resume()
}
}