Search code examples
iosobjective-cautolayoutconstraints

iOS Autolayout: Is it okay to set constraint priority to 999 to silence a warning?


I am getting the following warning with auto layout.

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:0x604000285230 H:|-(64)-[UILabel:0x7fc908d51ba0]   (active, names: '|':UIView:0x7fc908d52020 )>",
    "<NSLayoutConstraint:0x6040002854b0 H:[UIView:0x7fc908c59f60]-(0)-|   (active, names: '|':UIView:0x7fc908d52020 )>",
    "<NSLayoutConstraint:0x604000285000 H:[UILabel:0x7fc908d51ba0]-(9)-[UIView:0x7fc908c59f60]   (active)>",
    "<NSLayoutConstraint:0x6040002855f0 UIView:0x7fc908c59f60.width == 160   (active)>",
    "<NSLayoutConstraint:0x60400028a1e0 'UIView-Encapsulated-Layout-Width' UIView:0x7fc908d52020.width == 0   (active)>"
)

However, I am able to silence the warning by setting the trailing constraint priority to 999. This seems to remove the warning and nothing regarding the layout changed. Is this okay to do or can this cause any issues?


Solution

  • Is this okay to do or can this cause any issues? Depends. Might cause issues.

    The ideal way is to not disrupt you constraints to fix warnings. The issue seems to be with constraints.

    "<NSLayoutConstraint:0x60400028a1e0 'UIView-Encapsulated-Layout-Width' UIView:0x7fc908d52020.width == 0   (active)>"
    

    Your superview (0x7fc908d52020), is forcing a width of 0. Probably something you do not want.