Bryce Thomas
Bryce Thomas

Reputation: 10789

iOS find file in code that corresponds to a view in the simulator

I am working on a medium-size iOS code base and am not the primary developer. I often find myself in a position where I run the app in the iOS simulator, see a view I know I would like to edit or use (e.g. a textview whose text I would like to get), but then don't have a good way of tracing said view back to a file in the code base. My question is, are there any good ways (either deterministically or heuristically) to "back trace" from a view one sees in the running instantiation of the app in the iOS simulator back to the code file/interface builder file that actually defines/contains said view?

For example, I see a textview in the simulator whose text I'd like to set differently, and I want a way to find the .xib/storyboard the textview is defined in and/or any IBOutlet's to it. I have tried using Reveal App, which seems to give some information about the app's overall view structure and view classes, but I haven't been able to reference this back to a code and/or interface builder file. Reveal App does show the memory address of views - perhaps there is a way to use this in combination with lldb to figure out which file the view came from?

Upvotes: 7

Views: 898

Answers (2)

govi
govi

Reputation: 686

I know its a very old question. However, if you are still looking for an answer, you could break execution at any arbitrary point and use the lldb to print out some information.

Then, if, for example, your app, like most other apps, has a UINavigationController as a root view controller, then you could try and see whats the top view controller. If that's a TabView, then a little more digging.. u get the drift...

po [(UINavigationController *)[[[UIApplication sharedApplication] keyWindow] rootViewController] topViewController]

This seems to work fairly well. Not too straightforward, but not a bad deal.

Upvotes: 3

user2535467
user2535467

Reputation:

One way for you to do this would be to Ctrl+click on the outlet that you would like to edit (the text view or whatever) and see where the connections lead to. Or you could click on the item in need of edit and check the Connections Inspector in the right side and see what it is connected to.

That won't tell you exactly where it is, but it will give you the idea. Then you could just comb through the code in the area it pointed to, and see where it is referenced and whatnot.

Also if you do it this way, you can see what the outlet is called, which would then enable to search the code or the project for that outlet.

Upvotes: 0

Related Questions