Tom
Tom

Reputation: 3637

xcode reporting constraint error at runtime - but can't find it?

I am getting this error during runtime:

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x7ff70350c8a0 UITableViewCellContentView:0x7ff7058511c0.trailingMargin == UIView:0x7ff705851f00.trailing>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
2016-08-29 16:53:12.533 xxxx[7125:4051730] 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. 
(
    "<NSLayoutConstraint:0x7ff705a0aca0 UITableViewCellContentView:0x7ff705853420.trailingMargin == UIView:0x7ff7058546f0.trailing - 10>",
    "<NSLayoutConstraint:0x7ff705a0ad90 UITableViewCellContentView:0x7ff705853420.trailingMargin == UIView:0x7ff7058546f0.trailing>"
)

However, I have been unable to identify from where it gets

UITableViewCellContentView:0x7ff705853420.trailingMargin == UIView:0x7ff7058546f0.trailing

I can not find in the IDE. I have tried searching code for where I set constraints - but nothing that match the error as far as I can tell.

Is it possible there is a constraint defined that Xcode IDE does not show?

Upvotes: 0

Views: 284

Answers (2)

JuicyFruit
JuicyFruit

Reputation: 2668

You can try opening MainStoryBoard as source code and search there. The problem is you have 2 same constrains (trailing margin to UIView), one of them is 0, other is 10. It is possible it was not deleted from source code of storyboard.

Upvotes: 1

xoudini
xoudini

Reputation: 7031

You can extend NSLayoutConstraint and override description to return slightly more human readable information when a constraint breaks:

extension NSLayoutConstraint {
    override public var description: String {
        let id = identifier ?? "NO ID"
        return "id: \(id), constant: \(constant)"
    }
}

The tedious part of this is that you have to manually set an id for each constraint, though you can limit the amount of work needed by commenting out the extension and only setting identifiers for constraints that are related to the standard constraint warning.

Upvotes: 1

Related Questions