title: How to add a comment to a Post using Parse and Swift
body: <p>I've been working on an app that lets users post on the main timeline, and I've been working in the comment portion of the posts. Since I was stuck I followed a tutorial I found online:</p>
  
  <p><a href="http://shrikar.com/using-uitableview-and-footerview-to-implement-commenting-system-building-yik-yak-clone-part-3/" rel="nofollow">http://shrikar.com/using-uitableview-and-footerview-to-implement-commenting-system-building-yik-yak-clone-part-3/</a></p>
  
  <p>He implements the comment portion of an app, so I thought I could do something similar. 
  However, after coding the comment portion like in the tutorial, the comments are not being displayed, neither the original post in the comments section.</p>
  
  <p>On parse, I have a 'Posts' class that has the following tables:</p>
  
  <ul>
  <li>Users</li>
  <li>content (posts)</li>
  <li>likes (this a number)</li>
  <li>replies (# of comments)</li>
  <li>comments (which is an array that should hold all of the comments)</li>
  </ul>
  
  <p>Here I attach the code that I have, and I also wonder if there's a way to keep the reply bar at the bottom of the screen, since it's attached to the table view. How can I get it to display the comments to the tableView?</p>
  
  <p>Any help is appreciate it! </p>
  
  <pre><code>import UIKit
  import Parse
  
  class DetailViewContoller: UIViewController, UITableViewDelegate, UITextViewDelegate {
  
  @IBOutlet weak var usernameLabel: UILabel!
  @IBOutlet weak var postLabel: UILabel!
  @IBOutlet weak var commentTableView: UITableView!
  
  var post: PFObject?
  var commentView: UITextView?
  var footerView: UIView?
  var contentHeight: CGFloat = 0
  
  var comments: [String]?
  let FOOTERHEIGHT : CGFloat = 50;
  
  override func viewDidLoad() {
      super.viewDidLoad()
  
      commentTableView.delegate = self
  
      /* Setup the keyboard notifications */
      NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyBoardWillShow:", name: UIKeyboardWillShowNotification, object: nil)
      NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyBoardWillHide:", name: UIKeyboardWillHideNotification, object: nil)
  
  
      /* Setup the contentInsets */
      self.commentTableView.contentInset = UIEdgeInsetsZero
      self.commentTableView.scrollIndicatorInsets = UIEdgeInsetsZero
  
  
      self.edgesForExtendedLayout = UIRectEdge.None
      /* Make sure the content doesn't go below tabbar/navbar */
      self.extendedLayoutIncludesOpaqueBars = true
  
      self.automaticallyAdjustsScrollViewInsets = false
  
  
      if(post?.objectForKey("comments") != nil) {
          comments = post?.objectForKey("comments") as? [String]
      }
      println(post)
      println(post?.objectForKey("content"))
      self.postLabel.text = post?.objectForKey("content") as? String
  }
  
  
  func keyBoardWillShow(notification: NSNotification) {
      var info:NSDictionary = notification.userInfo!
      var keyboardSize = (info[UIKeyboardFrameBeginUserInfoKey] as! NSValue).CGRectValue()
  
      var keyboardHeight:CGFloat =  keyboardSize.height - 40
  
  
      var animationDuration:CGFloat = info[UIKeyboardAnimationDurationUserInfoKey] as! CGFloat
  
      var contentInsets: UIEdgeInsets = UIEdgeInsetsMake(0.0, 0.0, keyboardHeight, 0.0);
      self.commentTableView.contentInset = contentInsets
      self.commentTableView.scrollIndicatorInsets = contentInsets
  
  }
  
  func keyBoardWillHide(notification: NSNotification) {
  
      self.commentTableView.contentInset = UIEdgeInsetsZero
      self.commentTableView.scrollIndicatorInsets = UIEdgeInsetsZero
  }
  
  override func didReceiveMemoryWarning() {
      super.didReceiveMemoryWarning()
  
  }
  
  func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {
      if let count = comments?.count {
          return count
      }
      return 0
  }
  
  func numberOfSectionsInTableView(tableView: UITableView) -&gt; Int {
      return 1
  }
  
  func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -&gt; UITableViewCell {
      let cell = commentTableView.dequeueReusableCellWithIdentifier("commentCell", forIndexPath: indexPath) as! CommentTableViewCell
      cell.commentLabel?.text = comments![indexPath.row]
      return cell
  }
  
  func tableView(tableView: UITableView, heightForFooterInSection section: Int) -&gt; CGFloat {
      if self.footerView != nil {
          return self.footerView!.bounds.height
      }
      return FOOTERHEIGHT
  }
  
  func tableView(tableView: UITableView, viewForFooterInSection section: Int) -&gt; UIView? {
      footerView = UIView(frame: CGRect(x: 0, y: 0, width: commentTableView.bounds.width, height: FOOTERHEIGHT))
      footerView?.backgroundColor = UIColor(red: 243.0/255, green: 243.0/255, blue: 243.0/255, alpha: 1)
      commentView = UITextView(frame: CGRect(x: 10, y: 5, width: commentTableView.bounds.width - 80 , height: 40))
      commentView?.backgroundColor = UIColor.whiteColor()
      commentView?.textContainerInset = UIEdgeInsetsMake(5, 5, 5, 5)
      commentView?.layer.cornerRadius = 2
      commentView?.scrollsToTop = false
  
      footerView?.addSubview(commentView!)
      let button = UIButton(frame: CGRect(x: commentTableView.bounds.width - 65, y: 10, width: 60 , height: 30))
      button.setTitle("Reply", forState: UIControlState.Normal)
      button.backgroundColor = UIColor(red:  0/0.0, green: 179/255.0, blue: 204/255.0, alpha: 100.0/100.0)
      button.layer.cornerRadius = 5
      button.addTarget(self, action: "reply", forControlEvents: UIControlEvents.TouchUpInside)
      footerView?.addSubview(button)
      commentView?.delegate = self
      return footerView
  }
  
  func textViewDidChange(textView: UITextView) {
  
      if (contentHeight == 0) {
          contentHeight = commentView!.contentSize.height
      }
  
      if(commentView!.contentSize.height != contentHeight &amp;&amp; commentView!.contentSize.height &gt; footerView!.bounds.height) {
          UIView.animateWithDuration(0.2, animations: { () -&gt; Void in
              let myview = self.footerView
              println(self.commentView!.contentSize.height)
              println(self.commentView?.font.lineHeight)
              let newHeight : CGFloat = self.commentView!.font.lineHeight
              let myFrame = CGRect(x: myview!.frame.minX, y: myview!.frame.minY - newHeight , width: myview!.bounds.width, height: newHeight + myview!.bounds.height)
              myview?.frame = myFrame
  
              let mycommview = self.commentView
              let newCommHeight : CGFloat = self.commentView!.contentSize.height
              let myCommFrame = CGRect(x: mycommview!.frame.minX, y: mycommview!.frame.minY, width: mycommview!.bounds.width, height: newCommHeight)
              mycommview?.frame = myCommFrame
  
              self.commentView = mycommview
              self.footerView  = myview
  
              for item in self.footerView!.subviews {
                  if(item.isKindOfClass(UIButton.self)){
                      let button = item as! UIButton
                      let newY = self.footerView!.bounds.height / 2 - button.bounds.height / 2
                      let buttonFrame = CGRect(x: button.frame.minX, y: newY , width: button.bounds.width, height : button.bounds.height)
                      button.frame = buttonFrame
  
                  }
              }
          })
  
          println(self.footerView?.frame)
          println(self.commentView?.frame)
          contentHeight = commentView!.contentSize.height
      }
  }
  
  func reply() {
      post?.addObject(commentView!.text, forKey: "comments")
      post?.saveInBackground()
      if let tmpText = commentView?.text {
          comments?.append(tmpText)
      }
      commentView?.text = ""
      println(comments?.count)
      self.commentView?.resignFirstResponder()
      self.commentTableView.reloadData()
  }
  </code></pre>
  
  <p>}</p>