title: Index out of range when i use to celll( Swift)
body: <p>people, I have this issue when I try back image from different cell
  (Thread 1: Fatal error: Index out of range)</p>
  
  <p>what I'm doing here ?
  I'm trying to build an Instagram clone and in my home view controller that what should posts show up. I make navigation with a table view and that table view has 2 cell with the different identifier. cell number 1 it's a header that brings data from users table to my username label and profile image. and cell number 2 its for posts its should bring post data like image and caption. I use firebase database.</p>
  
  <p>my code :</p>
  
  <pre><code>import UIKit
  
  import FirebaseAuth
  
  import FirebaseDatabase
  
  class HomeViewController: UIViewController ,UITableViewDelegate  {
  
  
      @IBOutlet weak var tableview: UITableView!
      var posts = [Post]()
      var users = [UserD]()
      override func viewDidLoad() {
          super.viewDidLoad()
  
          tableview.dataSource = self
          loadposts()
          userDetal()
  
       //   var post = Post(captiontxt: "test", photoUrlString: "urll")
       //   print(post.caption)
       //   print(post.photoUrl)
  
      }
  
      func loadposts() {
          Database.database().reference().child("posts").observe(.childAdded){ (snapshot: DataSnapshot)in
              print(Thread.isMainThread)
                if let dict = snapshot.value  as? [String: Any]{
                  let captiontxt = dict["caption"] as! String
                  let photoUrlString = dict["photoUrl"] as! String
                 let post = Post(captiontxt: captiontxt, photoUrlString: photoUrlString)
                  self.posts.append(post)
                  print(self.posts)
                  self.tableview.reloadData()
              }
          }
      }
      func userDetal() {
          Database.database().reference().child("users").observe(.childAdded){ (snapshot: DataSnapshot)in
              print(Thread.isMainThread)
              if let dict = snapshot.value  as? [String: Any]{
                  let usernametxt = dict["username"] as! String
                  let profileImageUrlString = dict["profileImageUrl"] as! String
                  let user = UserD(usernametxt: usernametxt, profileImageUrlString: profileImageUrlString)
                  self.users.append(user)
                  print(self.users)
                  self.tableview.reloadData()
              }
          }
      }
  
      @IBAction func logout(_ sender: Any) {
          do {
              try Auth.auth().signOut()
          }catch let logoutErrorr{
              print(logoutErrorr)
          }
          let storyboard = UIStoryboard(name: "Start", bundle: nil)
          let signinVC = storyboard.instantiateViewController(withIdentifier: "SigninViewController")
          self.present(signinVC, animated: true, completion: nil)
  
  
      }
  
  }
  
  extension HomeViewController: UITableViewDataSource{
      func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {
  
          return posts.count
  
      }
      func numberOfSections(in tableView: UITableView) -&gt; Int {
          return users.count
      }
      func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -&gt; UITableViewCell {
          if indexPath.row == 0{
           let cell = tableview.dequeueReusableCell(withIdentifier: "imagecell", for: indexPath) as! PostCellTableViewCell
  
          cell.postimage.image = nil
  
          cell.tag += 1
          let tag = cell.tag
  
          cell.captionLabel.text = posts[indexPath.row].caption
  
          let photoUrl = posts[indexPath.row].photoUrl
  
          getImage(url: photoUrl) { photo in
              if photo != nil {
                  if cell.tag == tag {
                      DispatchQueue.main.async {
                          cell.postimage.image = photo
  
                      }
                  }
              }
          }
          return cell
          } else if indexPath.row == 1 {
              let cell = tableview.dequeueReusableCell(withIdentifier: "postcell", for: indexPath) as! HeaderTableViewCell
  
              cell.userimage.image = nil
  
              cell.tag += 1
              let tag = cell.tag
              cell.usernamelabel.text = users[indexPath.row].username 
              //Error showing here????????????????????????????????????
              let profileImageUrl = users[indexPath.row].profileImageUrl
  
              getImage(url: profileImageUrl) { photo in
                  if photo != nil {
                      if cell.tag == tag {
                          DispatchQueue.main.async {
                              cell.userimage.image = photo
  
  
                          }
                      }
                  }
              }
  
              return cell
          }
          return UITableViewCell()
  
      }
  
  
      func getImage(url: String, completion: @escaping (UIImage?) -&gt; ()) {
          URLSession.shared.dataTask(with: URL(string: url)!) { data, response, error in
              if error == nil {
                  completion(UIImage(data: data!))
              } else {
                  completion(nil)
              }
              }.resume()
  }
  }
  </code></pre>