title: How to switch between two auto-layout constraints?
body: <p>I have two UI layout constraints that are conflicting with each other by design. Only one of could be active at a time.</p>
  
  <p>In <code>UIViewController's</code> method <code>updateConstraintsIfNeeded</code>, I have the following code which toggles between the two constraints, depending on the state of a data model.</p>
  
  <pre><code>override func updateConstraintsIfNeeded() {
      super.updateConstraintsIfNeeded()
  
      if question?.thumbURL != nil {
          showAttachmentConstraint.active = true
          hideAttachmentConstraint.active = false        
      } else {
          showAttachmentConstraint.active = false
          hideAttachmentConstraint.active = true
      }
  }
  </code></pre>
  
  <p>This work as intended, but I got this familiar warning in the debug output:</p>
  
  <blockquote>
    <p>Unable to simultaneously satisfy constraints. Probably at least one of the constraints in the following list is one you don't want. ...</p>
  </blockquote>
  
  <p>Apparently when the statement <code>showAttachmentConstraint.active = true</code> is executed, it temporarily conflicts with <code>hideAttachmentConstraint</code> which is still active at that time. </p>
  
  <p>Is it possible to make this toggle operation atomic? I'm hoping there is something like <code>beginUpdate</code> and <code>endUpdate</code> in <code>UITableView</code>.</p>