Image for post
Image for post

Symbolic Breakpoint Xcode in 2 Minutes

Michael Abadi S.
Nov 9, 2020 · 3 min read

Once upon a time, while I was debugging my code, I found out an annoying warning comes up like below

[TableView] Warning once only: UITableView was told to layout its visible cells and other contents without being in the view hierarchy (the table view or one of its superviews has not been added to a window). This may cause bugs by forcing views inside the table view to load and perform layout without accurate information (e.g. table view bounds, trait collection, layout margins, safe area insets, etc), and will also cause unnecessary performance overhead due to extra layout passes. Make a symbolic breakpoint at UITableViewAlertForLayoutOutsideViewHierarchy to catch this in the debugger and see what caused this to occur, so you can avoid this action altogether if possible, or defer it until the table view has been added to a window.

There was no fixed solution out there on how to resolve this and what kind of things that cause this to happen. One thing I could understand, is the UITableView is forced to layout-ing its visible cells but actually, they were not in the view hierarchy yet !. What was the possible impact if we annoy this bug?

  1. Performance, performance, and performance while UIKit draws our views
  2. Undetected weird glitch may occur
  3. Fighting with your colleagues. UPS, Kidding lol

How to solve this issue then? Pretty easy, read all of the available logs provided by the compiler, pay attention to the last sentence. Explicitly, Xcode has given us the solution.

Make a symbolic breakpoint at UITableViewAlertForLayoutOutsideViewHierarchy to catch this in the debugger and see what caused this to occur, so you can avoid this action altogether if possible, or defer it until the table view has been added to a window.

Yes that’s it lets turn on our Symbolic breakpoint. Symbolic breakpoints are breakpoints that will trigger on certain conditions. How to do that?

  1. Navigate to the second last tab on the left panel with a breakpoint picture.
  2. Click the “+” icon at the lower left of the Breakpoint Navigator and select Symbolic Breakpoint.

After you finally click on it, fill in the name and the symbol. There are lots of other important symbols that Apple has, but for the sake of this debugging let’s put what Apple wants for our case

Image for post
Image for post

Now let’s run your project, anytime that the project nearly produces the warning, it will call the breakpoints, and you will get the stack trace and identify your problem. In my case, it was because I forced the view to layout the view if needed while the table view hasn’t been ready.

Good luck!

The Startup

Medium's largest active publication, followed by +752K people. Follow to join our community.

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store