title: Getting index out of error when reloading table view
body: <pre><code>func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
      tableView.deselectRow(at: indexPath, animated: true)
      let order =  orders[indexPath.row]
      guard orders.count &gt; indexPath.row else {
          print(&quot;Index out of range&quot;)
          return
      }
      
      let storyboard = UIStoryboard(name: &quot;Main&quot;, bundle: nil)
      var viewController = storyboard.instantiateViewController(withIdentifier: &quot;viewControllerIdentifer&quot;) as! OrderDetailsController
      viewController.passedValue = order.id
      self.present(viewController, animated: true , completion: nil)      
  }
  </code></pre>
  <p>Whenever I close my app (go to background) and reopen it it crashes.</p>
  <blockquote>
  <p>fatal error: Index out of range</p>
  <p>2017-06-18 18:09:33.726310 JaeeDriver[1378:563304] fatal error: Index out of range</p>
  </blockquote>
  <p>I have no idea why it does this. It's important to note that in <code>ViewDidLoud</code>I have this line of code to update my table</p>
  <pre><code>var timer = Timer.scheduledTimer(
      timeInterval: 4, 
      target: self, 
      selector: &quot;GetOrders&quot;, 
      userInfo: nil, 
      repeats: true
  )
  </code></pre>
  <p>and whenever the update happens, I have this code in the beginning of <code>GetOrders</code> function</p>
  <pre><code>func GetOrders (){   
      orders = []
      ...
  }
  </code></pre>
  <p>to remove the old data and replace it with the new one</p>
  <p><em>Update</em></p>
  <p>at the end of <code>GetOrder</code></p>
  <pre><code>func GetOrders (){   
      orders = []
      ....
      ....
      DispatchQueue.main.async {
          self.tableview.reloadData()
      }
  }
         
  </code></pre>
  <p>number of sections and rows :</p>
  <pre><code>func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {
      return orders.count
  }
  
  func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -&gt; UITableViewCell {
       let cell = tableView.dequeueReusableCell(withIdentifier: &quot;OrderCell&quot;, for: indexPath) as! OrderCell
      
      let entry = orders[indexPath.row]
      
      cell.DateLab.text = entry.date
       cell.shopNameLab.text = entry.shopname
      cell.shopAddLab.text = entry.shopaddress
      cell.nameClientLab.text = entry.clientName
      cell.clientAddLab.text = entry.ClientAddress
      cell.costLab.text = entry.Cost
      cell.perefTimeLab.text = entry.PerferTime
      cell.Shopimage.hnk_setImage(from: URL(string: entry.Logo))
      return cell
  }
  </code></pre>
  <p>Any help please would be appreciated.</p>