Здравствуйте! Передо мной стоит задача получить данные о количестве изображения через API, мой текущий код исполняется, ошибок нет, но и искомые значения я не получаю. Подскажите пожалуйста, что я делаю не так:
//
// ProfileViewController.swift
// mediasoft_proj
//
// Created by user on 28.06.2022.
// Copyright © 2022 user. All rights reserved.
//
import UIKit
struct APIresp: Codable {
let total: Int
let total_pages: Int
let results: [Result]
}
struct Result: Codable {
let id: String
let urls: URLS
}
struct URLS: Codable {
let full: String
}
class ProfileViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
@IBOutlet weak var tableView: UITableView!
var results: [Result] = []
override func viewDidLoad() {
super.viewDidLoad()
GetPhotos()
}
public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return results.count
}
public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "CellIdentifier", for: indexPath)
cell.textLabel?.text = "a"
return cell
}
func GetPhotos() {
guard let url = URL(string: "https://api.unsplash.com/search/photos?page=1&query=office&client_id=/*ключ API*/") else { return }
let task = URLSession.shared
task.dataTask(with: url) { [weak self] data, _, error in
guard let data = data, error == nil else {return}
do {
let jsonResult = try JSONDecoder().decode(APIresp.self, from: data)
DispatchQueue.main.async {
self?.results = jsonResult.results
}
}
catch {
print(error)
}
}.resume()
}
}