Things can get quite complicated when you have complex views. It's not always going to be simple to spot and fix an error. In Advanced debugging tips, you will learn advanced debugging techniques in Xcode that will help with your general iOS development but will also be specifically useful when debugging layout issues when running your LayoutTest tests.
- [Instructor] In this video you'll learn a few quick advanced debugging techniques that are useful for debugging your layouts, as well as throughout all iOS development debugging. First up is recursive description. You may have heard of this already, but recursive description is a property on UIWindow. In iOS development, you usually have one UIWindow at a time. So if we print out the recursive description in the one UIWindow, you will see all of the view hierarchy. You can do this by using the po command followed by UIWindow.keyWindow.recursiveDescription, which will show a detailed description of every view in your hierarchy.
This can be very useful if you have a lot of views and your not sure which one is causing the problem. You may also find that this may give you information about autolayout errors as well. Next is the po command. The po command prints properties in the debugger, but you can also use the p command which is a little bit more verbose and low level than the po command. It works the same way and has the same usage. Just use p or po followed by a space and any code you want and it will execute it.
This is useful for when debugging tough problems. A lesser known feature of Breakpoints in Xcode is that there are some special breakpoints you can set. On the left sidebar in Xcode, you can go the Breakpoint navigator. When you click the plus button in the bottom left hand corner, you'll see a couple of interesting Breakpoints you can add. The one we're interested in here is the Test Failure Breakpoint. So you will hit a Breakpoint any time your test fails. One last bonus debugging tip I want to give that's not actually useful for layout tests since you're not running an actual application, is the following, if you have an app and it fails and breaks at the UIApplicationMain, seemingly giving you no information about what went wrong, try doing this, type po space $arg1.
The arg1 register will have the information for the last exception that occurred. So in many cases, this will give you a printout of what actually went wrong. We all know debugging can be difficult, time-consuming and frustrating. Hopefully, these tips can help you to make it easier.
- Installing the library
- Specifying test data
- Reviewing property-based testing
- Using test data and writing the LayoutTest test
- Testing views at different sizes
- Debugging with snapshots
- Dealing with common errors
- Advanced debugging tips
- Exploring catalog view