Bo2SS

Bo2SS

How many ways are there to cook iOS? Each one is super delicious! (4)

Chenzhou chopped rice noodles, if you're a brother, come and chop


Last time we talked about common UI components in iOS, I don't know if you can already create some simple UI interfaces~

However, it is difficult to avoid encountering bugs or getting results that do not directly meet expectations during practice. This is where we need to use the debugging feature!

Next, let's enter the "Introduction to iOS with Xcode Debugging" series from "Xia Piao Piao" (4) - Xcode Debugging.

⚠️: The debugging techniques covered in this section are not limited to iOS development and should be included in most IDEs.

Adding Breakpoints#

Adding breakpoints is simple, just click on the corresponding line number in the code; to delete a breakpoint, drag the breakpoint marker out of the area.

Conditional Breakpoints#

Right-click on the breakpoint and select "Edit Breakpoint" to enter an appropriate condition. When the breakpoint is reached, the breakpoint will only be triggered if the condition is met, pausing the code execution.

Tasks Automatically Executed at Breakpoints#

Right-click on the breakpoint and select "Edit Breakpoint" to add an action, such as p cnt (debug command type), which will print the cnt variable when the breakpoint is reached.

Check the "Options" below to continue running the code after executing the above action without pausing.

Ignoring Breakpoints#

Right-click on the breakpoint and select "Edit Breakpoint". By following the red box, the breakpoint will be ignored on the first trigger and will only pause on the second trigger, usually used to ignore initialization.

Exception Breakpoints#

Exception breakpoints can be added in the lower left corner of the breakpoint navigator.

When an exception occurs, it will not cause a crash but will pause at the point where the crash is about to occur. At this time, you can clearly view the call stack (see the next section for details) and locate the root cause of the crash.

Symbol Breakpoints#

Symbol breakpoints can be added in the lower left corner of the breakpoint navigator by setting the symbol to a certain type of method, such as - [UIViewController viewDidLoad], which sets a common breakpoint for this class method without adding breakpoints at each call.

PS: Refer to Advanced Xcode Debugging Techniques, Did You Know? - Jian Shu

Sour: Call Stack Inspection#

When entering a breakpoint, there are 3 ways to view the current call stack.

Breakpoint Navigator#

The breakpoint navigator area displays all threads and the method call stack in each thread. 0 represents the top of the stack, which is the current method, and larger numbers call smaller numbers.

PS: In the above figure, methods 2 to 28 omitted are called by the iOS system's underlying layer. Since iOS is not open source, the call stack of the underlying layer cannot be seen.

Bottom Toolbar#

The project name in the bottom toolbar displays the same effect as the breakpoint navigator.

Debug Area#

The debug area can display the current call stack in text format by entering the command thread backtrace.

In addition, you can also use thread info [i] to view basic information about thread i.

PS: Refer to Printing Function Call Stack in iOS, Viewing Where Variables Are Called - CSDN

Spicy: 3D View Hierarchy Inspection#

When using the app, click on the red box button in the bottom toolbar to view the 3D view hierarchy (right 3D image) of the current interface of the app (left simulator in the figure).

Through the bottom toolbar, from left to right, we can: adjust the distance between view hierarchies | display clipped content, display constraints, change view mode, change background | select 2D/3D view | zoom | adjust the range of visible views.

In addition, right-click on a layer, the options are shown in the figure below. Click on Reveal in Debug Navigator to view the position of the layer among all layers, making it easy to understand the nesting relationship between layers.

Overall, 3D view hierarchy inspection is very suitable for checking UI issues.


Well, the short time always flies by so quickly. Wasn't this issue very short and practical? Especially some advanced debugging techniques for breakpoints.

👏 I hope it helps you, feel free to leave a comment and exchange ideas!

See You Next Week#

Let's take another look at the "Xia Piao Piao" app:

As you can see, in addition to the UI interface, it also includes these features: fetching network movie data, pull-to-refresh, pull-to-load-more, spinner loading interaction, and so on. So are these features difficult to implement? 👀

Perhaps they are difficult to implement, but it doesn't matter. There are many open-source third-party libraries available online that have already implemented the above features. We just need to know how to fetch and use them.


This is what we are going to talk about next week: CocoaPods - a third-party library dependency management tool for iOS development.

🎺 Stay tuned.

- It's getting cold too fast in Hunan, going back to Shenzhen to avoid the cold🚄

October 9, 2021

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.