title: Removing rows from Tableview after time expires
body: <p>I have searched every source I know of for help on this problem. I want to make individual rows within a tableview disappear after a certain amount of time expires. Even if the app is not open, I want the rows to delete as soon as the timer reaches zero. I have been trying to arrange each post into an dictionary with timer pairings to handle the row deletion when time occurs. I have looked at this post for guidance but no solutions. <a href="https://stackoverflow.com/questions/38348067/swift-deleting-table-view-cell-when-timer-expires/45722329?noredirect=1#comment78403215_45722329">Swift deleting table view cell when timer expires</a>.</p>
  
  <p>This is my code for handling the tableview and the timers:</p>
  
  <pre><code>var nextID: String?
  var postsInFeed = [String]()
  var postTimer = [Timer: String]()
  var timeLeft = [String: Int]()
  </code></pre>
  
  <p>(in view did load)</p>
  
  <pre><code>DataService.ds.REF_FEED.observe(.value, with: { (snapshot) in
          self.posts = []
          self.postsInFeed = []
          self.nextID = nil
  
          if let snapshot = snapshot.children.allObjects as? [DataSnapshot] { //Gets us into our users class of our DB
              for snap in snapshot { // Iterates over each user
                  if let postDict = snap.value as? Dictionary&lt;String, Any&gt; { // Opens up the dictonary key value pairs for each user.
                      let key = snap.key //
                      let post = Post(postID: key, postData: postDict) // Sets the properties in the dictionary to a variable.
                      self.posts.append(post) // appends each post which contains a caption, imageurl and likes to the empty posts array.
  
  
                      self.nextID = snap.key
                      let activeID = self.nextID
                      self.postsInFeed.append(activeID!)
  
                      print(self.postsInFeed)
                      print(activeID!)
  
  
                  }
  
              }
  
          }
          self.tableView.reloadData()
  
      })
  
  //////////////////////////////////////////////////////////////////////////////////////////////
  // Sets up our tableview
  func numberOfSections(in tableView: UITableView) -&gt; Int {
      return 1
  }
  
  func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {
      return postsInFeed.count
  }
  
  
  func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -&gt; UITableViewCell {
  
      let post = posts[indexPath.row] // We get our post object from the array we populate when we call the data from the database up above.
  
      if let cell = tableView.dequeueReusableCell(withIdentifier: "tableCell") as? TableViewCell { //Specifies the format of the cell we want from the UI
  </code></pre>
  
  <p>//            cell.cellID = self.postsInFeed[indexPath.row]</p>
  
  <pre><code>        cell.cellID = self.postsInFeed[indexPath.row]
  
  
          cell.homeVC = self
  
  
          if let img = HomeVC.imageCache.object(forKey: post.imageUrl as NSString){
              cell.configureCell(post: post, img: img as? UIImage)
              print(postTimer)
              print(self.timeLeft)
  
          }  else {
  
              cell.configureCell(post: post)
              print(postTimer)
              print(self.timeLeft)
          }
  
  
          return cell
  
  
      } else {
          return TableViewCell()
      }
  }
  
      func handleCountdown(timer: Timer) {
      let cellID = postTimer[timer]
  
      // find the current row corresponding to the cellID
      let row = postsInFeed.index(of: cellID!)
  
      // decrement time left
      let timeRemaining = timeLeft[(cellID!)]! - 1
      timeLeft[cellID!] = timeRemaining
      if timeRemaining == 0 {
          timer.invalidate()
  
          postTimer[timer] = nil
          postsInFeed.remove(at: row!)
          tableView.deleteRows(at: [IndexPath(row: row!, section: 0)], with: .fade)
  
      } else {
          tableView.reloadRows(at: [IndexPath(row: row!, section: 0)], with: .fade)
      }
  }
  </code></pre>
  
  <p>In the tableviewcell:</p>
  
  <pre><code>weak var homeVC: HomeVC?
  var cellID: String!
  
      func callTime() {
      homeVC?.timeLeft[cellID] = 25
      let timer = Timer.scheduledTimer(timeInterval: 1.0, target: self, selector: #selector(homeVC?.handleCountdown(timer:)), userInfo: nil, repeats: true)
      homeVC?.postTimer[timer] = cellID
  
  }
  </code></pre>
  
  <p>Any help would be really appreciated!</p>