ios – Swift – Methods to create Array listing to fill the TableView from API knowledge

0
9


Hey guys good morning 🙂 , how can I make it to fill the info fetched from API to TableView, so I can study it as soon as and for all.

So the info come from API in that kind proven under and I simply want some steerage to make the info out there in each cell of my tableview.these are the cells that must be crammed

let token = "NjQzODM2N0NDNDM4NDhCNDFSA3jA0QUY0NjVEFF="

static let shared = APICaller()
personal let baseURL = "http://111.111.111.111:3030/api/"

personal init() {}

func getVehicles(for id: String, accomplished: @escaping (Consequence<[Vehicles],Errors>) -> Void ){
    let endpoint = baseURL + "GetVehicles?UserIdentificationValue=(id)"
    
    
    guard let url = URL(string: endpoint) else {
        accomplished(.failure(.invalidURL))
        return
    }
    
    var request = URLRequest(url: url)
    request.httpMethod = "GET"


    request.addValue("software/json", forHTTPHeaderField: "Settle for")
    request.setValue("Bearer (token)",   forHTTPHeaderField: "Authorization")
    
    
    let session = URLSession.shared
        let job = session.dataTask(with: request) { knowledge, response, error in
            
            if let _ = error {
                accomplished(.failure(.unableToComplete))
                return
            }
            guard let response = response as? HTTPURLResponse, response.statusCode == 200 else {
                accomplished(.failure(.invalidResponse))
                return
            }
            guard let knowledge = knowledge else {
                accomplished(.failure(.invalidData))
                return
            }
            do {
                let decoder = JSONDecoder()
                decoder.keyDecodingStrategy = .useDefaultKeys

                let autos = strive decoder.decode([Vehicles].self, from: knowledge)
                accomplished(.success(autos))
                
            } catch let error {
                accomplished(.failure(.invalidData))
            }
        }
        job.resume()

    }

That is the construction knowledge that I need to fill in desk view:

struct Autos: Codable {

var  IDVehicle: Int?
var  Title: String?
var  RegistrationDate: String?
var  ExpireDate: String?
var  Division: String?
var  Identification: String?
var  Pace: String?
var  Latitude: Double?
var  Longitude: Double?
var  Angle: Int?
var  Standing: Int?
var  InputValue: Int?
var  Plate: String?
var  LastCommunicationDate: String?
var  Passengers: Int?
var  Driver: String?

}

LEAVE A REPLY

Please enter your comment!
Please enter your name here