Search code examples
swiftuiviewuiview-hierarchyview-hierarchy

How to find where UIView has been created in code - swift - Programmatically


If I see a UIView in Debug View Hierarchy and I don't know where it comes from, Is there a way to see where it has been programmatically created in code?

This question describes and explains the reverse case (you have the code of the view and you see where it is located in the view hierarchy).

How can I find where I (accidentally) created a view in my code using the code provided by the view in the Debug View Hierarchy?


Solution

  • That is an extremely good question, but unfortunately the answer is no. There is nothing about the view debugger that tells you how any particular view came into existence.

    A good way to track the creation of views might be to put symbolic breakpoints on their designated initializers:

    enter image description here

    You will break a lot, but each time you do you can look to see if this is the problematic view and then continue. Eventually, it will be! And now you can see who is calling the initializer.