title: how do I add a comment to it like in Instagram and allow other users to comment on the pictures as well
body: <p>Hi when posting a picture in my swift 3 and firebase app how do I add a comment to it like before the picture is actually posted? Like in Instagram and how do I allow other users to comment on the pictures that other people have posted as well? below is every code I have on posting</p>
  
  <p><strong>Post Cell</strong></p>
  
  <pre><code>import UIKit
  import Firebase
  import FirebaseStorage
  import FirebaseDatabase
  import SwiftKeychainWrapper
  
  class PostCell: UITableViewCell {
  
  @IBOutlet weak var userImg: UIImageView!
  
  @IBOutlet weak var username: UILabel!
  
  @IBOutlet weak var postImg: UIImageView!
  
  @IBOutlet weak var likesLbl: UILabel!
  
  var post: Post!
  
  var userPostKey: FIRDatabaseReference!
  
  let currentUser = KeychainWrapper.standard.string(forKey: "uid")
  
  
  override func awakeFromNib() {
      super.awakeFromNib()
  }
  
  override func setSelected(_ selected: Bool, animated: Bool) {
      super.setSelected(selected, animated: animated)
  
      // Configure the view for the selected state
  }
  
  func configCell(post: Post, img: UIImage? = nil, userImg: UIImage? = nil) {
  
      self.post = post
  
      self.likesLbl.text = "\(post.likes)"
  
      self.username.text = post.username
  
      if img != nil {
  
          self.postImg.image = img
  
      } else {
  
          let ref = FIRStorage.storage().reference(forURL: post.postImg)
          ref.data(withMaxSize: 10 * 10000, completion: { (data, error) in
  
              if error != nil {
  
                  print(error)
  
              } else {
  
                  if let imgData = data {
  
                      if let img = UIImage(data: imgData){
  
                          self.postImg.image = img
                      }
                  }
              }
          })
      }
  
      if userImg != nil {
  
          self.postImg.image = userImg
  
      } else {
  
          let ref = FIRStorage.storage().reference(forURL: post.userImg)
          ref.data(withMaxSize: 100000000, completion: { (data, error) in
  
              if error != nil {
  
                  print("couldnt load img")
  
              } else {
  
                  if let imgData = data {
  
                      if let img = UIImage(data: imgData){
  
                          self.userImg.image = img
                      }
                  }
              }
          })
      }
  
      _ = FIRDatabase.database().reference().child("users").child(currentUser!).child("likes").child(post.postKey)
  }
  
  @IBAction func liked(_ sender: Any) {
  
      let likeRef = FIRDatabase.database().reference().child("users").child(currentUser!).child("likes").child(post.postKey)
  
      likeRef.observeSingleEvent(of: .value, with:  { (snapshot) in
  
          if let _ = snapshot.value as? NSNull {
  
              self.post.adjustLikes(addlike: true)
  
              likeRef.setValue(true)
  
          } else {
  
              self.post.adjustLikes(addlike: false)
  
              likeRef.removeValue()
          }
      })
  }
  }
  </code></pre>
  
  <p><strong>FeedVC</strong></p>
  
  <pre><code>import UIKit
  import Firebase
  import FirebaseDatabase
  import FirebaseStorage
  import SwiftKeychainWrapper
  import CoreImage
  
  class FeedVC: UIViewController, UITableViewDelegate, UITableViewDataSource, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
  
  @IBOutlet weak var tableView: UITableView!
  
  @IBOutlet weak var postBtn: UIButton!
  
  var posts = [Post]()
  
  var post: Post!
  
  var imagePicker: UIImagePickerController!
  
  var imageSelected = false
  
  var selectedImage: UIImage!
  
  var userImage: String!
  
  var userName: String!
  
  override func viewDidLoad() {
      super.viewDidLoad()
  
      tableView.delegate = self
  
      tableView.dataSource = self
  
      imagePicker = UIImagePickerController()
  
      imagePicker.allowsEditing = true
  
      imagePicker.delegate = self
  
  
  
  
      FIRDatabase.database().reference().child("posts").observe(.value, with: {(snapshot) in
  
          if let snapshot = snapshot.children.allObjects as? [FIRDataSnapshot] {
  
              self.posts.removeAll()
  
              for data in snapshot {
  
                  print(data)
  
                  if let postDict = data.value as? Dictionary&lt;String, AnyObject&gt; {
  
                      let key = data.key
  
                      let post = Post(postKey: key, postData: postDict)
  
                      self.posts.append(post)
                  }
              }
          }
  
          self.tableView.reloadData()
      })
  }
  
  
  
  func numberOfSections(in tableView: UITableView) -&gt; Int {
  
      return 1
  }
  
  func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {
  
      return posts.count
  }
  
  func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -&gt; UITableViewCell {
  
      let post = posts[indexPath.row]
  
      if let cell = tableView.dequeueReusableCell(withIdentifier: "PostCell") as? PostCell {
  
          cell.configCell(post: post)
  
          return cell
  
      } else {
  
          return PostCell()
      }
  }
  
  override var preferredStatusBarStyle : UIStatusBarStyle {
      return UIStatusBarStyle.lightContent
  }
  
  func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
  
      if let image = info[UIImagePickerControllerEditedImage] as? UIImage {
  
          selectedImage = image
  
          imageSelected = true
  
      } else {
  
          print("A valid image wasnt selected")
      }
      imagePicker.dismiss(animated: true, completion: nil)
  
      guard imageSelected == true else {
  
          print("An image must be selected")
  
          return
      }
  
      if let imgData = UIImageJPEGRepresentation(selectedImage, 0.2) {
  
          let imgUid = NSUUID().uuidString
  
          let metadata = FIRStorageMetadata()
  
          metadata.contentType = "image/jpeg"
  
          FIRStorage.storage().reference().child("post-pics").child(imgUid).put(imgData, metadata: metadata) { (metadata, error) in
  
              if error != nil {
  
                  print("image did not save to firebase storage")
  
              } else {
  
                  print("uploded to firebase storage")
  
                  let downloadURL = metadata?.downloadURL()?.absoluteString
  
                  if let url = downloadURL {
  
                      self.postToFirebase(imgUrl: url)
                  }
              }
          }
      }
  }
  
  func postToFirebase(imgUrl: String) {
  
      let userID = FIRAuth.auth()?.currentUser?.uid
  
      FIRDatabase.database().reference().child("users").child(userID!).observeSingleEvent(of: .value, with: { (snapshot) in
  
          let data = snapshot.value as! Dictionary&lt;String, AnyObject&gt;
  
          let username = data["username"]
  
          let userImg = data["userImg"]
  
          let post: Dictionary&lt;String, AnyObject&gt; = [
              "username": username as AnyObject,
              "userImg": userImg as AnyObject,
              "imageUrl": imgUrl as AnyObject,
              "likes": 0 as AnyObject
          ]
  
          let firebasePost = FIRDatabase.database().reference().child("posts").childByAutoId()
  
          firebasePost.setValue(post)
  
          self.imageSelected = false
  
          self.tableView.reloadData()
  
      }) { (error) in
  
          print(error.localizedDescription)
      }
  }
  
  @IBAction func postImageTapped(_ sender: AnyObject)
  {
  
          let alert = UIAlertController(title: "Choose Image", message: nil, preferredStyle: .actionSheet)
          alert.addAction(UIAlertAction(title: "Camera", style: .default, handler: { _ in
             self.openCamera()
          }))
  
          alert.addAction(UIAlertAction(title: "Gallery", style: .default, handler: { _ in
             self.openGallary()
          }))
  
          alert.addAction(UIAlertAction.init(title: "Cancel", style: .cancel, handler: nil))
  
          self.present(alert, animated: true, completion: nil)
      }
  
      func openCamera()
      {
          if(UIImagePickerController .isSourceTypeAvailable(UIImagePickerControllerSourceType.camera))
          {
              imagePicker.sourceType = UIImagePickerControllerSourceType.camera
              imagePicker.allowsEditing = true
              self.present(imagePicker, animated: true, completion: nil)
          }
          else
          {
              let alert  = UIAlertController(title: "Warning", message: "You don't have camera", preferredStyle: .alert)
              alert.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
              self.present(alert, animated: true, completion: nil)
          }
      }
  
      func openGallary()
      {
          imagePicker.sourceType = UIImagePickerControllerSourceType.photoLibrary
          imagePicker.allowsEditing = true
          self.present(imagePicker, animated: true, completion: nil)
      }
  
  
  @IBAction func SignOutPressed(_ sender: AnyObject) {
  
      try! FIRAuth.auth()?.signOut()
  
      KeychainWrapper.standard.removeObject(forKey: "uid")
  
      dismiss(animated: true, completion: nil)
  }
  }
  </code></pre>
  
  <p><strong>Post</strong></p>
  
  <pre><code>import Foundation
  import Firebase
  import FirebaseDatabase
  
  class Post {
  private var _username: String!
  private var _userImg: String!
  private var _postImg: String!
  private var _likes: Int!
  private var _postKey:  String!
  private var _postRef: FIRDatabaseReference!
  
  var username: String {
      return _username
  }
  
  var userImg: String {
      return _userImg
  }
  
  var postImg: String {
      get {
          return _postImg
      } set {
          _postImg = newValue
      }
  }
  
  var likes: Int {
      return _likes
  }
  
  var postKey: String {
      return _postKey
  }
  
  init(imgUrl: String, likes: Int, username: String, userImg: String) {
      _likes = likes
      _postImg = imgUrl
      _username = username
      _userImg = userImg
  }
  
  init(postKey: String, postData: Dictionary&lt;String, AnyObject&gt;) {
      _postKey = postKey
  
      if let username = postData["username"] as? String {
          _username = username
      }
  
      if let userImg = postData["userImg"] as? String {
          _userImg = userImg
      }
  
      if let postImage = postData["imageUrl"] as? String {
          _postImg = postImage
      }
  
      if let likes = postData["likes"] as? Int {
          _likes = likes
      }
  
      _postRef = FIRDatabase.database().reference().child("posts").child(_postKey)
  
  }
  
  func adjustLikes(addlike: Bool) {
      if addlike {
          _likes = likes + 1
      } else {
          _likes = likes - 1
      }
      _postRef.child("likes").setValue(_likes)
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Hope this is enough information provided.</p>