title: Should I enclose "addArrangedSubview" to the animation block or not?
body: <p>I'm not learning the use of <code>UIStackView</code> and read <a href="http://code.tutsplus.com/tutorials/ios-9-getting-started-with-uistackview--cms-24193" rel="nofollow">a good tutorial</a> on the web. In the tutorial, the author writes the following code to make an animation:</p>
  
  <pre><code>@IBAction func addStar(sender: AnyObject) {
      let starImgVw:UIImageView = UIImageView(image: UIImage(named: "star"))
      starImgVw.contentMode = .ScaleAspectFit
      self.horizontalStackView.addArrangedSubview(starImgVw)
      UIView.animateWithDuration(0.25, animations: {
          self.horizontalStackView.layoutIfNeeded()
      })
  }
  </code></pre>
  
  <p>However, when I cloned the repository and changed the code slightly, I still saw the same animation properly.</p>
  
  <pre><code>@IBAction func addStar(sender: AnyObject) {
      let starImgVw:UIImageView = UIImageView(image: UIImage(named: "star"))
      starImgVw.contentMode = .ScaleAspectFit
      UIView.animateWithDuration(0.25, animations: {
          self.horizontalStackView.addArrangedSubview(starImgVw)
          self.horizontalStackView.layoutIfNeeded()
      })
  }
  </code></pre>
  
  <p>I moved <code>self.horizontalStackView.addArrangedSubview(starImgVw)</code> to the inner part of the animation block.</p>
  
  <p>I also tried the same thing on <code>removeStar</code> function; this time moved both <code>self.horizontalStackView.removeArrangedSubview(aStar)</code> and <code>aStar.removeFromSuperview()</code>, but I also confirmed the animation work properly.</p>
  
  <p>So my question is the following:</p>
  
  <ul>
  <li><p>Which is the better way?</p></li>
  <li><p>Why do these two code work in the same way?</p></li>
  <li><p>When I removed <code>layoutIfNeeded()</code>, then the animation didn't work. This is because if I don't force the views to be updated immediately, then the next view update cycle occurs after the animation block and thus the animation is no longer valid, right?</p></li>
  </ul>