Fixing NavigationTitle Warning Errors In SwiftUI

For some strange reason when you add the navigationTitle() to any view inside the NavigationView it would throw constraint errors.

Running the simulator it would build fine but will throw these constraint warnings.

2022-04-08 21:33:33.403719+1200 AU Driver Knowledge Test[46914:3648036] [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. 
(
    "<NSLayoutConstraint:0x600001f524e0 'BIB_Leading_Leading' H:|-(0)-[_UIModernBarButton:0x16141c0e0]   (active, names: '|':_UIButtonBarButton:0x1614198b0 )>",
    "<NSLayoutConstraint:0x600001f53250 'UINav_static_button_horiz_position' _UIModernBarButton:0x16141c0e0.leading == UILayoutGuide:0x600000575b20'UIViewLayoutMarginsGuide'.leading   (active)>",
    "<NSLayoutConstraint:0x600001f532a0 'UINavItemContentGuide-leading' H:[_UIButtonBarButton:0x1614198b0]-(6)-[UILayoutGuide:0x600000575a40'UINavigationBarItemContentLayoutGuide']   (active)>",
    "<NSLayoutConstraint:0x600001f55770 'UINavItemContentGuide-trailing' UILayoutGuide:0x600000575a40'UINavigationBarItemContentLayoutGuide'.trailing == _UINavigationBarContentView:0x161413be0.trailing   (active)>",
    "<NSLayoutConstraint:0x600001f59090 'UIView-Encapsulated-Layout-Width' _UINavigationBarContentView:0x161413be0.width == 0   (active)>",
    "<NSLayoutConstraint:0x600001f55a90 'UIView-leftMargin-guide-constraint' H:|-(8)-[UILayoutGuide:0x600000575b20'UIViewLayoutMarginsGuide'](LTR)   (active, names: '|':_UINavigationBarContentView:0x161413be0 )>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x600001f524e0 'BIB_Leading_Leading' H:|-(0)-[_UIModernBarButton:0x16141c0e0]   (active, names: '|':_UIButtonBarButton:0x1614198b0 )>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful.
2022-04-08 21:33:33.404101+1200 AU Driver Knowledge Test[46914:3648036] [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. 
(
    "<NSLayoutConstraint:0x600001f52530 'BIB_Trailing_CB_Leading' H:[_UIModernBarButton:0x16141c0e0]-(6)-[_UIModernBarButton:0x161419c90'Test Title']   (active)>",
    "<NSLayoutConstraint:0x600001f52580 'CB_Trailing_Trailing' _UIModernBarButton:0x161419c90'Test Title'.trailing <= _UIButtonBarButton:0x1614198b0.trailing   (active)>",
    "<NSLayoutConstraint:0x600001f53250 'UINav_static_button_horiz_position' _UIModernBarButton:0x16141c0e0.leading == UILayoutGuide:0x600000575b20'UIViewLayoutMarginsGuide'.leading   (active)>",
    "<NSLayoutConstraint:0x600001f532a0 'UINavItemContentGuide-leading' H:[_UIButtonBarButton:0x1614198b0]-(6)-[UILayoutGuide:0x600000575a40'UINavigationBarItemContentLayoutGuide']   (active)>",
    "<NSLayoutConstraint:0x600001f55770 'UINavItemContentGuide-trailing' UILayoutGuide:0x600000575a40'UINavigationBarItemContentLayoutGuide'.trailing == _UINavigationBarContentView:0x161413be0.trailing   (active)>",
    "<NSLayoutConstraint:0x600001f59090 'UIView-Encapsulated-Layout-Width' _UINavigationBarContentView:0x161413be0.width == 0   (active)>",
    "<NSLayoutConstraint:0x600001f55a90 'UIView-leftMargin-guide-constraint' H:|-(8)-[UILayoutGuide:0x600000575b20'UIViewLayoutMarginsGuide'](LTR)   (active, names: '|':_UINavigationBarContentView:0x161413be0 )>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x600001f52530 'BIB_Trailing_CB_Leading' H:[_UIModernBarButton:0x16141c0e0]-(6)-[_UIModernBarButton:0x161419c90'Test Title']   (active)>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful.
2022-04-08 21:33:33.428550+1200 AU Driver Knowledge Test[46914:3648036] [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. 
(
    "<NSLayoutConstraint:0x600001f51a40 UIView:0x16120fbb0.trailing == _UIBackButtonMaskView:0x16120f450.trailing   (active)>",
    "<NSLayoutConstraint:0x600001f52b20 'Mask_Trailing_Trailing' _UIBackButtonMaskView:0x16120f450.trailing == _UIButtonBarButton:0x1614198b0.trailing   (active)>",
    "<NSLayoutConstraint:0x600001f52c60 'MaskEV_Leading_BIB_Trailing' H:[_UIModernBarButton:0x16141c0e0]-(0)-[UIView:0x16120fbb0]   (active)>",
    "<NSLayoutConstraint:0x600001f53250 'UINav_static_button_horiz_position' _UIModernBarButton:0x16141c0e0.leading == UILayoutGuide:0x600000575b20'UIViewLayoutMarginsGuide'.leading   (active)>",
    "<NSLayoutConstraint:0x600001f532a0 'UINavItemContentGuide-leading' H:[_UIButtonBarButton:0x1614198b0]-(6)-[UILayoutGuide:0x600000575a40'UINavigationBarItemContentLayoutGuide']   (active)>",
    "<NSLayoutConstraint:0x600001f55770 'UINavItemContentGuide-trailing' UILayoutGuide:0x600000575a40'UINavigationBarItemContentLayoutGuide'.trailing == _UINavigationBarContentView:0x161413be0.trailing   (active)>",
    "<NSLayoutConstraint:0x600001f59090 'UIView-Encapsulated-Layout-Width' _UINavigationBarContentView:0x161413be0.width == 0   (active)>",
    "<NSLayoutConstraint:0x600001f55a90 'UIView-leftMargin-guide-constraint' H:|-(8)-[UILayoutGuide:0x600000575b20'UIViewLayoutMarginsGuide'](LTR)   (active, names: '|':_UINavigationBarContentView:0x161413be0 )>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x600001f51a40 UIView:0x16120fbb0.trailing == _UIBackButtonMaskView:0x16120f450.trailing   (active)>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful.

The Debug View Hierarchy shows the following which is still unclear to me how it works.

Thanks to this post. Adding navigationViewStyle() modifier with a style of .stack seems to fix the issue.

Leave a Reply

Your email address will not be published. Required fields are marked *