Last Updated: May 02, 2017
·
403
· krunal_Chaudharia

Swift 3 tableview show empty data at the time of calling web-services, here is my code of tableview with weburl please help me

let url = URL(string:"http://trading.wolfsoft.ws/api/customer/product")!

var request = URLRequest(url:url)

request.httpMethod = "GET"

print("Service Called")

let task = URLSession.shared.dataTask(with: request) { data, response, error in
    guard let data = data else

    {
        print("Solution Fail \(String(describing: error))")
        return
    }

    do {

        if let json = try JSONSerialization.jsonObject(with: data) as? [NSDictionary] {

            DispatchQueue.main.async {

                for result in json {

                    let pids = result["product_id"] as! String
                    let chave = result["customer_have"] as! String
                    let cnitem = result["customer_need_item"] as! String
                    let cnprice = result["customer_need_price"] as! String
                    let cname = result["city_name"] as! String
                    let pimage = result["product_image"] as! String

                    print("calling")

                    self.pid.append(pids)
                    self.cuhave.append(chave)
                    self.citem.append(cnitem)
                    self.cnaprice.append(cnprice)
                    self.cityname.append(cname)
                    self.pimages.append(pimage)

                 }
              }
          }

    }