Reading an 'Unable to simultaneously satisfy constraints' log
A UILabel is pinned to its superview's leading and trailing edges and is also given a fixed width of 200 pt. At runtime the console prints the log below.
Read the log: identify the conflicting constraints and the one the engine broke to recover, and explain how you map those addresses back to your source.
Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want.
(
"<NSLayoutConstraint:0x6000 UILabel:0x7fa8.width == 200>",
"<NSLayoutConstraint:0x6001 H:|-(16)-[UILabel:0x7fa8]>",
"<NSLayoutConstraint:0x6002 H:[UILabel:0x7fa8]-(16)-|>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x6000 UILabel:0x7fa8.width == 200>
Diagnose the cause and name the fix.
The log lists every conflicting constraint and names the one it broke. Give each an .identifier to map the addresses to code, then find the over-constrained axis — a fixed 200-pt width fighting the leading and trailing pins. Remove one or lower its priority.
- ✗Ignoring the warning because the app still renders something
- ✗Deleting the first listed constraint without finding the real conflict
- ✗Leaving constraints unnamed so the addresses can't be traced to code
- →How does a symbolic breakpoint on the layout assertion help you catch it live?
- →Why does lowering a priority resolve a conflict better than deleting a constraint?
The log names three constraints on the horizontal axis of one UILabel: a fixed width == 200, a leading pin, and a trailing pin. Leading + trailing already determine the width from the superview, so the extra fixed width over-constrains the axis — there is no single width that satisfies all three. Auto Layout keeps the required-priority pins and breaks the one it can, reported after "Will attempt to recover by breaking constraint".
Make the log readable, then remove the redundant constraint:
// 1. Name constraints so the log prints identifiers, not raw addresses.
let width = label.widthAnchor.constraint(equalToConstant: 200)
width.identifier = "label.fixedWidth"
// 2. The real fix: don't pin both edges AND a fixed width. Keep the edges…
NSLayoutConstraint.activate([
label.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 16),
label.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -16),
])
// …or, if 200 pt is intentional, drop trailing and lower the width's priority
// so it yields when space is tight:
width.priority = .defaultHigh
Set a symbolic breakpoint on UIViewAlertForUnsatisfiableConstraints to pause the moment the conflict is logged and inspect the offending views in the debugger.