Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find views in Debug View Hierarchy based on their address?

Tags:

xcode

ios

We all get them sometimes..

** [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:0x608000287670 H:|-(16)-[UIView:0x7fe38456eeb0](LTR)   (active, names: '|':MyApp.MyCell:0x7fe3848d9400'MyCellIdentifier' )>",
    "<NSLayoutConstraint:0x6080002876c0 UIView:0x7fe38456eeb0.right == MyApp.MyCell:0x7fe3848d9400'MyCellIdentifier'.right   (active)>",
    "<NSLayoutConstraint:0x608000288520 'UIView-Encapsulated-Layout-Width' MyApp.MyCell:0x7fe3848d9400'MyCellIdentifier'.width == 0   (active)>"
)

You don't have to read into what it means, it doesn't really have anything to do with this question. This started showing up in my log after I did some major changes to my app. I have googled it, and I understand that this particular issue is a weird one where I have to find a certain constraint, and set its priority to 999, so that the system can set the cell's width to 0 if it wants to. This is fine.

My question is not directly directed towards this particular issue. Whenever I get something like this in the log, there's always an address following the class name. Like the one shown in the example above: MyApp.MyCell:0x7fe3848d9400.

Can I use this address and search the view hierarchy to find the view? I know that if I click Debug View Hierarchy I get a sweet "stasis" view of my app. The problem is that my app is getting pretty big, and I have a lot of views. Especially in UITableView's. There are so many views present, each with their own address.

If I select any view in the debug hierarchy, I can easily see its address, as seen in the top right corner in the image below.

Since I already have the address of the view I want to find, is there a way to locate it? The way I'm doing it now, is to go through all the relevant views on my debug-screen, copy their address, and CMD+F CMD+V into my output log to see if that particular view was mentioned in my log output.

Grid view

There has to be a better way..

like image 493
Sti Avatar asked Oct 30 '17 14:10

Sti


People also ask

How do you debug a view hierarchy?

First, launch a project with some interesting UI. Project 13, for example, has enough in there to be interesting. Now run the program as normal, then in Xcode go to the Debug menu and choose View Debugging > Capture View Hierarchy. After a few seconds of thinking, Xcode will show you a screenshot of your app's UI.

What is hierarchy in Swift?

UIView hierarchy is a tree with it's root in a window ( UIWindow is a subclass of UIView ). We can traverse this tree using subviews and superview properties. UIViewController hierarchy starts from the rootViewController of a window.


1 Answers

If you type (or copy/paste) the hex address into the search field at the bottom of the Navigator Pane, it should filter / find the object:

enter image description here

like image 181
DonMag Avatar answered Sep 28 '22 11:09

DonMag