swift parse data and append array is always 0

This is my array decleration.

var names = [String]()

My Json parsing code . Olaylar is a struct (Decodable) . I run this code in viewDidAppear

guard let url = URL(string: "http://MYurl.abc.php") else { return }
        let session = URLSession.shared
        let task = session.dataTask(with: url) { (data, _, _) in
            guard let data = data else {
                return }
            do {

                let users = try JSONDecoder().decode([Olaylar].self, from: data)
                for user in users {
                    self.names.append(user.id)
                    print(self.names) // can show all datas

                }
            } catch {}
        }
        task.resume()

extension OlayDetay: UITableViewDelegate,UITableViewDataSource {

  func numberOfSectionsInTableView(tableView: UITableView) -> Int {
    return 1
  }

  func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return names.count
  }
  func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

    let cell = tableView.dequeueReusableCell(withIdentifier: "olayDetay", for: indexPath) as! OlayDetayCell
    cell.label1.text = names[indexPath.row]
    print(names.count) // return 0 

    return cell
  }
}

My names array always return 0 each I tried to append some data