-1

I have this function

 func calc1(){

    var urll = [String]()
    for var i = 0; i < restu_id.count; ++i{

        var url = "https://maps.googleapis.com/maps/api/distancematrix/json?origins=\(lat[i]),\(long[i])&destinations=6.447768,3.48124859999996&mode=driving&language=pl-PLe"
        urll.append(url)
    }

    for im in urll{
        print(im)
        rtu(im)
        var delivP:Int?
        let url = NSURL(string: im)
        let task = NSURLSession.sharedSession().dataTaskWithURL(url!) {
            (data, response, error) in
            let jsonObj = JSON(data: data!)
            let yy = jsonObj["rows"][0]["elements"][0]["distance"]["value"].int
            var converted = (yy! / 1000) * 65
            if converted < 400{
                converted = 400
            }

            self.iu.append(converted)
            print("IU:\(self.iu)")

        }
        task.resume()
        }
    }

When i print iu in the closure it prints fine but when i try to use iu to setup my cell in cellForRowAtIndexPath i get nil And am calling the calc1 function in viewdidload

Sagaya Abdul
  • 37
  • 3
  • 8
  • You probably just need to call `reloadData` on your table view after you append the converted data to the array. – AdamPro13 Sep 12 '16 at 20:23

1 Answers1

0

Sounds like you aren't reloading your tableView, perhaps on the last request you may call

tableView.reloadData()
ohr
  • 1,717
  • 14
  • 15