I’m debugging a complex application with lots of protocols, view controllers etc… The app is a variation of VIPER architecture. The app is written in Swift 3 and uses iOS 10.3. The codebase is huge and it is about two years old of active development and architectural tweaks, however I’m new to the app.
One of the bugs is that one of the workflows in the app shows a wrong screen at the end of it. I am able to replicate the bug every time in the simulator.
My question is how to find the code (ex. ViewController or ViewPresenter) of the view currently displayed in the simulator? Can I pause the program with lldb and somehow get to the code?
@tomn Thanks very much for your question! When it comes to finding the identity of the view, the easiest approach that I’ve used (and I currently am working on a project that also utilizes a similar variation of VIPER) is:
Identify text contained in the view. This could be labels, Navigation Bar title, text of any kind. Once you have identified this text, search your project for occurrences of this text in Xcode to see where it is found, and through a process of elimination, determine what class controls the view. Once you’ve narrowed it down, place a break point at the “viewDidLoad” of the class you think controls the view. This way, you’ll know when the view is about to appear, the break point will be hit.
Another approach is to identify the screen that comes BEFORE it. It appears you have identified the screen prior to it, so go through the code, and step through the code in that class, and determine which method is triggering the call to transition to the next View. Once you’ve identified the code that triggers the call, see where it leads to, and that should point to the code that is calling the screen in question.