I am making a shopping app but I've come to a problem.
So far I've been json parsing, making a the tableview cell but I've come to an error where it says out of range:
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "hello", for: indexPath) as! DisplayShopTableCellTableViewCell
// Configure the cell...
cell.userLbl.text = namee[indexPath.row] //Index out of range
cell.passLbl.text = myprice[indexPath.row]
let imagedata = try! Data(contentsOf: mySecond[indexPath.row].imageUrl!)
cell.tablecellimageview.image = UIImage(data: imagedata)
return cell
}
This is my display shop table cell:
class DisplayShopTableCellTableViewCell: UITableViewCell {
@IBOutlet weak var userLbl: UILabel!
@IBOutlet weak var passLbl: UILabel!
@IBOutlet weak var tablecellimageview: UIImageView!
Parsing
func extracted(){
guard let url = URL(string: "http://rajeshrmohan.com/sport.json")
else {
return
}
let task = URLSession.shared.dataTask(with: url){
(data,response,error) in
guard let dataResponse = data,
error == nil else {
print(error?.localizedDescription ?? "Response Error")
return
}
do {
let decoder = JSONDecoder()
let model = try decoder.decode(FullClothes.self, from: dataResponse)
//print(model)
for i in 0..<model.item.count{
self.namee.append(model.item[i].name!)
self.myprice.append(String(model.item[i].price!))
self.myphoto.append(model.item[i].image!)
}
DispatchQueue.main.async {
self.tableView.reloadData()
}
}
catch let parsingError {
print("Error", parsingError)
}
}
task.resume()
}