NEW: Learn to build the incredible iOS 15 Weather app today! >>

SwiftUI NSLayoutConstraints Violation since video "Ultimate Portfolio App - First steps in UI"

Forums > Videos

The following NSLayoutConstrains Violation has been bugging me for a while. I introduced it while following the "First steps in UI" video. Is anyone else also getting this printed in the console or knows how to fix this?

2021-03-20 09:19:33.908674+0100 FitnessTracker[84405:5160693] [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:0x6000013c7ac0 'BIB_Trailing_CB_Leading' H:[_UIModernBarButton:0x7fc8dbe20df0]-(6)-[_UIModernBarButton:0x7fc8dbe059f0'HOME']   (active)>",
    "<NSLayoutConstraint:0x6000013c7b10 'CB_Trailing_Trailing' _UIModernBarButton:0x7fc8dbe059f0'HOME'.trailing <= _UIButtonBarButton:0x7fc8dbe19b80.trailing   (active)>",
    "<NSLayoutConstraint:0x6000013d8780 'UINav_static_button_horiz_position' _UIModernBarButton:0x7fc8dbe20df0.leading == UILayoutGuide:0x6000009910a0'UIViewLayoutMarginsGuide'.leading   (active)>",
    "<NSLayoutConstraint:0x6000013d87d0 'UINavItemContentGuide-leading' H:[_UIButtonBarButton:0x7fc8dbe19b80]-(0)-[UILayoutGuide:0x600000990fc0'UINavigationBarItemContentLayoutGuide']   (active)>",
    "<NSLayoutConstraint:0x600001397ca0 'UINavItemContentGuide-trailing' UILayoutGuide:0x600000990fc0'UINavigationBarItemContentLayoutGuide'.trailing == _UINavigationBarContentView:0x7fc8dbe15530.trailing   (active)>",
    "<NSLayoutConstraint:0x6000013d8f50 'UIView-Encapsulated-Layout-Width' _UINavigationBarContentView:0x7fc8dbe15530.width == 0   (active)>",
    "<NSLayoutConstraint:0x6000013aec10 'UIView-leftMargin-guide-constraint' H:|-(0)-[UILayoutGuide:0x6000009910a0'UIViewLayoutMarginsGuide'](LTR)   (active, names: '|':_UINavigationBarContentView:0x7fc8dbe15530 )>"

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x6000013c7ac0 'BIB_Trailing_CB_Leading' H:[_UIModernBarButton:0x7fc8dbe20df0]-(6)-[_UIModernBarButton:0x7fc8dbe059f0'HOME']   (active)>


Using .navigationViewStyle(StackNavigationViewStyle()) helped me. See


Hacking with Swift is sponsored by Essential Developer

SPONSORED Only until this Sunday, December 12th, you can join a free crash course to learn advanced techniques for testing new and legacy Swift code — it's the fast track to becoming a complete Senior iOS Developer!

Click to learn more

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

Unknown user

You are not logged in

Log in or create account

Link copied to your pasteboard.