title: Programmatic Auto Layout Constraints to Edges of Superview
body: <p>I have done quite a bit of auto layout in Xcode's storyboard editor, but I rarely ever do anything in code. In one particular instance, I need to create the programmatic equivalent to these constraints:</p>
  
  <p><a href="https://i.stack.imgur.com/UzqI4.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/UzqI4.png" alt="enter image description here"></a></p>
  
  <p>These constraints are added to <code>textView</code> and the superview is another view called <code>commentBox</code>. I've tried this so far, but the code feels redundant and results in an auto layout error of conflicting constraints:</p>
  
  <pre><code>//Trailing
  textView.addConstraint(NSLayoutConstraint(item: textView, attribute: .trailing, relatedBy: .equal, toItem: cell.commentBox, attribute: .trailing, multiplier: 1, constant: 15))
  //Leading
  textView.addConstraint(NSLayoutConstraint(item: textView, attribute: .leading, relatedBy: .equal, toItem: cell.commentBox, attribute: .leading, multiplier: 1, constant: 15))
  //Bottom
  textView.addConstraint(NSLayoutConstraint(item: textView, attribute: .bottom, relatedBy: .equal, toItem: cell.commentBox, attribute: .bottom, multiplier: 1, constant: 10))
  //Top
  textView.addConstraint(NSLayoutConstraint(item: textView, attribute: .top, relatedBy: .equal, toItem: cell.commentBox, attribute: .top, multiplier: 1, constant: 10))
  </code></pre>
  
  <p>Any idea what am I doing wrong? Thanks!</p>