У меня есть json, который доставляет данные с сервера, поэтому у меня есть 3 разных класса и контроллер представления
это основной класс
public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return poi.count
}
//the method returning each cell of the list
public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! ViewControllerTableViewCell
//getting the hero for the specified position
let hero: poiLista
hero = poi[indexPath.row]
//displaying values
cell.labelName.text = hero.nombre
cell.labelID.text? = "\(hero.id_poi)"
return cell
}
Это часть функции, которую я использую для отображения данных
//creating NSMutableURLRequest
let request = NSMutableURLRequest(url: requestURL! as URL)
//setting the method to post
request.httpMethod = "GET"
//creating a task to send the post request
let task = URLSession.shared.dataTask(with: request as URLRequest){
data, response, error in
//exiting if there is some error
if error != nil{
print("error is \(error)")
return;
}
//parsing the response
do {
//converting resonse to NSDictionary
var teamJSON: NSDictionary!
teamJSON = try JSONSerialization.jsonObject(with: data!, options: .mutableContainers) as? NSDictionary
//getting the JSON array teams from the response
let teams: NSArray = teamJSON["teams"] as! NSArray
//looping through all the json objects in the array teams
for i in 0 ..< teams.count{
//getting the data at each index
let poiID: Int = (teams[i] as! NSDictionary)["id_poi"] as! Int
let poiName: String = (teams[i] as! NSDictionary)["nombre"] as! String
self.poi.append(poiLista(
id_poi: poiID,
nombre: poiName
))
//displaying the data
print("id -> ", poiID)
print("name -> ", poiName)
}
//displaying data in tableview
self.tableViewMuseo.reloadData()
} catch {
print(error)
}
}
//executing the task
task.resume()
из json Я получаю необработанные отслеживаемые данные, поэтому хочу, чтобы они отображались в таблице, но они не работают
id -> 1
название -> Школа