This Banner is For Sale !!
Get your ad here for a week in 20$ only and get upto 15k traffic Daily!!!

Track the view controllers’ lifecycle using symbolic breakpoints in Xcode


Think about you have simply began a brand new job in an organization and you’re going to work on a mission that was developed a very long time in the past. Unsurprisingly, you might be uncovered to colossal legacy code with numerous views and courses. Step one is all the time to know the code and know which works how. So that you begin to launch the mission and see the way it works. However you haven’t any concept which view controller you are seeing and the place are you within the software. Issues get even worse once you’re assigned a job, say a easy bug repair, and you need to begin straight away. Effectively, there’s a resolution to seek out precisely the place you need to begin digging the code to seek out and repair the difficulty.



Symbolic Breakpoints to the Rescue

By including a easy symbolic breakpoint in your mission you’ll preserve monitor of the mission as you are operating and navigating by way of the app.

1- In Xcode, go to Breakpoint Navigator pane and add a Symbolic Breakpoint

Add symbolic breakpoint

2- Within the window that seems set the next parameters:
In Image, kind the next:

-[UIViewController viewWillAppear:]

Then add a Debugger Motion with the next worth:

expr -- (void) printf("🚀 %sn", (char *)object_getClassName($arg1))

It is a easy ObjC expression that prints the present view controller class title.

3- Lastly, choose Mechanically proceed after evaluating motion to forestall the debugger from pausing the appliance when the breakpoint occurs.

Configure the breakpoint

This methodology will print the title of the present view controller on its viewWillAppear and allow you to know the place precisely you might be within the mission. This can forestall you from getting misplaced within the large codebases if you find yourself working with the initiatives that you have simply taken possession of (otherwise you already personal!).




Bonus: Reminiscence leak hunter!

Now enables you to present how one can know when the view controller is launched from the reminiscence. This one is extremely helpful once you wish to ensure that the view controllers are deallocated efficiently and likewise will provide help to to catch the doable retain cycles for instance.
You may obtain this by creating one other easy Symbolic breakpoint with out writing a single line of code inside your mission!

1- Add one other Symbolic Breakpoint with the next worth in Image:
-[UIViewController dealloc]

2- The remaining will stay the identical. We simply add a unique emoji to know it is for the deallocation of the item:
expr -- (void) printf("❎%sn", (char *)object_getClassName($arg1))

3- Keep in mind to pick out Mechanically proceed after evaluating actions.

You retain navigating the appliance and in the event you do not see this print once you go away a view controller, it implies that we now have a doable reminiscence leak. So you can begin investigating the issue comfortably.

Demonstration

Glad coding
Al

The Article was Inspired from tech community site.
Contact us if this is inspired from your article and we will give you credit for it for serving the community.

This Banner is For Sale !!
Get your ad here for a week in 20$ only and get upto 10k Tech related traffic daily !!!

Leave a Reply

Your email address will not be published. Required fields are marked *

Want to Contribute to us or want to have 15k+ Audience read your Article ? Or Just want to make a strong Backlink?