Is there a way to see object names in debug view hierarchy?
Asked Answered
O

3

7

The debug view hierarchy is a great way to view they different layers that make up the UI, but as far as I can't tell there is no way to see what outlet reference names the objects have. They are simply referred to as what type of object they are. For example, a button is just refered to as UIButton rather than the name of the outlet. Yes, it's possible to see in what viewController it resides, but it' not foolprof and it can still be very hard to track down certain objects.

So, is there a way to see what the reference outlets of the objects are called?

Ogbomosho answered 11/12, 2019 at 13:33 Comment(3)
UIView.accessibilityIdentifier does the trick.Leisurely
@Leisurely can you please add that as an answer?Birchfield
@Birchfield I added an answer.Leisurely
P
5

No, there is not (unfortunately).

The information is not maintained at runtime to my knowledge, so you also won't be able to use lldb from Xcode's console to figure it out.

Probably worth a feature request to Apple! https://feedbackassistant.apple.com/

Primitivism answered 3/1, 2020 at 7:47 Comment(1)
Ah, thanks! Agreed. View hierarchy would be a great tool if only this feature existed.Flambeau
L
8

UIView.accessibilityIdentifier does that trick.

For NSLayoutConstraints, its description in warning log (or po constraint) contains more details after set UIView.accessibilityIdentifer.
Before set accessibilityIdentifier, it's something like

<NSLayoutConstraint: 0x6000037766c0 UILayoutGuide: 0x600002d6c620'UIViewSafeAreaLayoutGuide'.trailing == UILabel: 0x7fee70712780.trailing + 132 (active)>

After set accessiblityIdentifier,

<NSLayoutConstraint:0x6000037766c0 UILayoutGuide:0x600002d6c620'UIViewSafeAreaLayoutGuide'.trailing == First-ID.trailing + 132 (active, names: First-ID:0x7fee70712780 )>

For view debugger, you can check accessibilityIdentifier as follows

enter image description here

Leisurely answered 13/1, 2021 at 4:32 Comment(0)
P
5

No, there is not (unfortunately).

The information is not maintained at runtime to my knowledge, so you also won't be able to use lldb from Xcode's console to figure it out.

Probably worth a feature request to Apple! https://feedbackassistant.apple.com/

Primitivism answered 3/1, 2020 at 7:47 Comment(1)
Ah, thanks! Agreed. View hierarchy would be a great tool if only this feature existed.Flambeau
T
-1

Here's a trick that can help you figure out the view in question You can rely on the memory address of the view

print the description of the view / or find the memory address while you're in the View Hierarchy Debugger

Resume the flow ... capture the flow in any break point you have Check for the corresponding view that is allocated in this memory address

Turnbull answered 15/8, 2024 at 15:10 Comment(1)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Contraindicate

© 2022 - 2025 — McMap. All rights reserved.