Auto Layout constraint issue with UIKeyboardAssistant on iPad

I ran into this issue with an iOS app I was working on. The app had a UISearchBar above a UITableView, and when tapping a cell it would segue to another view. On iPad, a UIKeyboardAssistantBar would appear if the user typed in the search bar. With text in the search bar, when we segued to the other view, Xcode would dump a bunch of “Unable to simultaneously satisfy constraints” errors:

2018-03-16 11:41:00.734267-0600 testconstraints[82244:11877036] [LayoutConstraints] 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. 

 (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) 

(

    "<NSAutoresizingMaskLayoutConstraint:0x60000029e550 h=--& v=--& UIKeyboardAssistantBar:0x7fa438f40a00.height == 0   (active)>",

    "<NSLayoutConstraint:0x60000028e740 V:|-(0)-[_UIButtonBarStackView:0x7fa438f436a0]   (active, names: '|':UIKeyboardAssistantBar:0x7fa438f40a00 )>",

    "<NSLayoutConstraint:0x60000028e8d0 V:[_UIButtonBarStackView:0x7fa438f436a0]-(0)-|   (active, names: '|':UIKeyboardAssistantBar:0x7fa438f40a00 )>",

    "<NSLayoutConstraint:0x60000029e1e0 'UISV-canvas-connection' UILayoutGuide:0x6000001b8e20'UIViewLayoutMarginsGuide'.top == _UILayoutSpacer:0x6000003d4460'UISV-alignment-spanner'.top   (active)>",

    "<NSLayoutConstraint:0x60000029e230 'UISV-canvas-connection' UILayoutGuide:0x6000001b8e20'UIViewLayoutMarginsGuide'.bottom == _UILayoutSpacer:0x6000003d4460'UISV-alignment-spanner'.bottom   (active)>",

    "<NSLayoutConstraint:0x60000028e290 'UIView-bottomMargin-guide-constraint' V:[UILayoutGuide:0x6000001b8e20'UIViewLayoutMarginsGuide']-(9)-|   (active, names: '|':_UIButtonBarStackView:0x7fa438f436a0 )>",

    "<NSLayoutConstraint:0x60000028e1f0 'UIView-topMargin-guide-constraint' V:|-(10)-[UILayoutGuide:0x6000001b8e20'UIViewLayoutMarginsGuide']   (active, names: '|':_UIButtonBarStackView:0x7fa438f436a0 )>"

)

Will attempt to recover by breaking constraint 

<NSLayoutConstraint:0x60000029e230 'UISV-canvas-connection' UILayoutGuide:0x6000001b8e20'UIViewLayoutMarginsGuide'.bottom == _UILayoutSpacer:0x6000003d4460'UISV-alignment-spanner'.bottom   (active)>

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.

In the end, all I had to do was make sure the searchBar made a call to resignFirstResponder() in prepare(for segue: UIStoryboardSegue, sender: Any?).