Just putting this here in case anyone has the same issue with a dynamic, code-generated aspectRatio
constraint. I switched the order of the Height and Width relationship in the aspect-ratio constraint (compare to the one in the question):
aspectConstraint = NSLayoutConstraint(item: cardMedia, attribute: NSLayoutAttribute.Height , relatedBy: NSLayoutRelation.Equal, toItem: cardMedia, attribute: NSLayoutAttribute.Width, multiplier: aspect, constant: 0.0)
Where the multiplier aspect
is calculated by:
let aspect = image.size.height / image.size.width
And that seems to stop the crash from happening. Hope this helps someone.