Search code examples
iosswiftnslayoutconstraintios10

iOS 10: NSInvalidLayoutConstraintException: Constraint improperly relates anchors of incompatible types


After updating to iOS 10 Im getting this error a bunch on one of my apps

NSInvalidLayoutConstraintException: Constraint improperly relates anchors of incompatible types:

<NSLayoutConstraint:0x170495270 UIView:0x1010e1d90.top == AppName.OtherView:0x1010dc6f0.centerX (active)>

I've never had an issue using a constraint like this before and I'm only getting it on my iOS 10 devices. Any ideas?


Solution

  • You perhaps are doing something like this:

    NSLayoutConstraint(item: viewA, attribute:
                    .leading , relatedBy: .equal, toItem: parentView, attribute: .top, multiplier: 1.0, constant: 20)
    

    So you do not stitch the correct anchors together like .leading and .top. In this case it must be .leading and .leading.

    Interestingly this wasn't a problem with iOS9.