How to update NSLayoutConstraint in a UITableViewCell of dynamic height?
<p>A <code>UITableViewCell</code> contains an <code>UIImageView</code> and has the height <code>UITableViewAutomaticDimension</code>.</p>

<p>I want to resize the image view according to the size of its image. The image view should then resize the height of the table view cell.</p>

<p>The vertical layout constraints of the image view in Interface Builder are:</p>

<ul>
<li>imageView.topAnchor = cell.contentView.topAnchor</li>
<li>imageView.bottomAnchor &lt;= cell.contentView.bottomAnchor + 10</li>
<li>imageView.heightAnchor = 100</li>
</ul>

<p>I've set a layout constraint as IBOutlet for the height anchor of the image view. As soon as I change its constant the layout breaks and the constraint is ignored. The height of the table view cell does not adapt its size and seems to break the constraint.</p>

<p>The constraint constant is changed at:</p>

<pre><code>func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -&gt; UITableViewCell {

    let cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier) as! MyCell
    cell.image = image
    cell.updateConstraint()
    return cell
}

class MyCell {

    func updateConstraint() {
        imageViewHeightConstraint.constant = image.size.height // This line already throws the UIViewAlertForUnsatisfiableConstraints exception
        imageImageView.setNeedsLayout()
    }
}
</code></pre>

<p>How is it done properly?</p>

<p><strong>Update:</strong>
The error log break the "width = height" constraint because the layout is actually a bit more complicated then described above: The widthAnchors' constant is changed and the widthAnchor = heightAnchor of the image view.</p>

<pre><code>Unable to simultaneously satisfy constraints.
    Probably at least one of the constraints in the following list is one you don't want. 
    Try this: 
        (1) look at each constraint and try to figure out which you don't expect; 
        (2) find the code that added the unwanted constraint or constraints and fix it. 
(
    "&lt;NSLayoutConstraint:0x7f98be1a22b0 H:[UIImageView:0x7f98be7d36e0(96)]&gt;",
    "&lt;NSLayoutConstraint:0x7f98be158470 UIImageView:0x7f98be7d36e0.width == UIImageView:0x7f98be7d36e0.height&gt;",
    "&lt;NSLayoutConstraint:0x7f98be1273e0 V:|-(5)-[UIImageView:0x7f98be7d36e0]   (Names: '|':UIView:0x7f98be12d860 )&gt;",
    "&lt;NSLayoutConstraint:0x7f98be133040 V:[UIImageView:0x7f98be7d36e0]-(5)-|   (Names: '|':UIView:0x7f98be12d860 )&gt;",
    "&lt;NSLayoutConstraint:0x7f98be1929e0 V:|-(5)-[UIView:0x7f98be12d860]   (Names: '|':UITableViewCellContentView:0x7f98be1582f0 )&gt;",
    "&lt;NSLayoutConstraint:0x7f98be12dd10 V:[UIView:0x7f98be12d860]-(&gt;=10)-|   (Names: '|':UITableViewCellContentView:0x7f98be1582f0 )&gt;",
    "&lt;NSLayoutConstraint:0x7f98be7d66a0 'UIView-Encapsulated-Layout-Height' V:[UITableViewCellContentView:0x7f98be1582f0(89)]&gt;"
)

Will attempt to recover by breaking constraint 
&lt;NSLayoutConstraint:0x7f98be158470 UIImageView:0x7f98be7d36e0.width == UIImageView:0x7f98be7d36e0.height&gt;

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in &lt;UIKit/UIView.h&gt; may also be helpful.
</code></pre>