title: Why am I unable to install a constraint on my view?
body: <p>I am trying to animate a button from outside the visible bounds of my <code>UIViewController</code> to the center of it. I have a constraint setup in my storyboard called <code>myButtonLeading</code> which I remove as part of my animation, and then I want to add a new constraint called <code>newCenterConstraint</code>.</p>
  
  <pre><code>@IBAction func updateDidTouch(_ sender: Any) {
  
      UIView.animate(withDuration: 0.5, delay: 0, options: UIViewAnimationOptions.curveEaseInOut, animations: {
  
          let newCenterConstraint = NSLayoutConstraint(item: self.myButton, attribute: .centerX, relatedBy: .equal, toItem: view, attribute: .centerX, multiplier: 1.0, constant: 0.0)
  
          self.myButton.removeConstraint(self.myButtonLeading)
          self.myButton.addConstraint(newCenterConstraint)
  
          self.view.layoutIfNeeded()
  
      }, completion: nil)
  }
  </code></pre>
  
  <p>The code I have right now is giving me the following error message regarding my reference to <code>toItem: view</code>.</p>
  
  <blockquote>
    <p>Implicit use of 'self' in closure; use 'self.' to make capture
    semantics explicit</p>
  </blockquote>
  
  <p>But when I used <code>self.view</code> my app crashes with an error message saying:</p>
  
  <blockquote>
    <p>Unable to install constraint on view.  Does the constraint reference
    something from outside the subtree of the view?  That's illegal.</p>
  </blockquote>
  
  <p>Where am I going wrong here in adding the new centerX constraint?</p>