swiftxcodeuitableviewxcode-storyboard

Ambiguous layout warnings in Xcode 13.0


After starting Xcode 13.0, I get plenty of Position and size are ambiguous for ... and Width and horizontal position are ambiguous ... layout warnings on an app, which didn't show up on previous Xcode version some days ago (I didn't change anything after Xcode upgrade). Mentioned objects show properly on device and simulator. Checking in detail, it reveals that all constraints seem to be correctly set.

enter image description here

enter image description here

Above example is pretty straight forward. I don't really see what the reason for the warning could possibly be.

Even more weird ... when I change the name of a label somewhere at the top of the tableview, most of the warnings (not all) just disappear. This label is in a cell which is totally unrelated to the objects generating the warnings. After restarting Xcode, the warnings are back again.

Also Update Frames doesn't solve the issue.

Is this an Xcode bug or do I miss something?

--- UPDATE 1 (20.10.2021) ---

  1. I noticed that the Main.storyboard shows ambiguous="YES" for concerned objects. Manual delete (while Xcode 13.0 is closed) doesn't help. ambiguous="YES" is back upon next Xcode start.

  2. I noticed that all warnings refer to constraints of objects, located after tableview cell 16 downwards (spread across 4 sections). This can't be a coincidence.

Are there any limits in the number of allowed cells inside a tableview and/or section?

--- UPDATE 2 (21.10.2021) ---

Some more details. After lots of testing and reading still no solution.

The entire issue is about a tableview controller, having 7 sections with a variable number of cells (2, 2, 1, 12, 1, 3, 2). The warnings show only after cell #11 in section #4, hence cell #16 counted from the top (disregarding section boundaries).

Xcode shows many incoherences in terms of change/impact relationship as shown below.

  1. There is a setting to disable warnings (TARGETS > Build Settings > IBSC_WARNINGS), but this doesn't change anything to the number of warnings shown. Manually (depreciated) delete of ambiguous="YES" in Main.storyboard file doesn't help. I don't see anything bad in giving that a try (after a backup of Main.storyboard). The question probably boils down to why Xcode adds the ambiguous tag to Main.storyboard at a first place.

  2. The project shows a yellow warning symbol top right corner of tab bar, as well as 10 warnings right of the target/device bar (very top of Xcode window). Clicking on that one opens the Issue navigator showing the 10 warnings. The storyboard shows however a red error symbol right of concerned tableview controller. Inside this list, only errors and no warnings (so now, errors or warnings?). The number is 16 errors, while the number of warnings in the top bar of Xcode shows 10 warnings. Trying to Add missing constraints doesn't do anything. My manually added constraints are apparently correct. See trivial example of OP (Reset settings). Lots of contradictory information across Xcode window.

  3. Changing the Document label (Identity inspector) of a switch belonging to a cell issuing a warning (e.g. cell #16), the total number of warnings goes down to 0! This label is only used by Xcode storyboard interface and doesn't show up on app UI. So why does it have an impact to constraint warnings? Non-related change solves a problem?

  4. If the warning count is 0 due (3.) above, restarting Xcode brings all back to previous state = 10 warnings. Why 0 warnings after a settting change, then again 10 warnings after restart?

  5. As said before, the mess starts in cell #16. However this one is a copy/paste from cell #15, which doesn't generate any warnings.

  6. View Debugging (Frames, Alignment rectangles) shows the interface correctly - on device and simulator.

When the app runs, the layout is actually displayed exactly as designed. These warnings don't seem to have any impact on actual operation. Also they didn't show prior Xcode 13.0.

There are quite some issues regarding layout ambiguities online, but rarely any solution. Most of the time, the author resigns by just accepting the nuisance. My intention is understand why these occur and to to fix potential hidden issues (if any).


Solution

  • I noticed the same bug on my app. It's happening in Static cells in TableView Controller, and ambiguous layout warning appears only for those cells that can be reached after scrolling down.

    Steps I took to remove layout warnings:

    1. Select the view controller that shows autolayout warnings
    2. Inspectors > Size > Simulated Size > Freeform (see image below)
    3. Change height so that all cells are displayed

    Now all those warnings are gone!

    Xcode version: 13.2 (13C90)

    Simulated Size image