NEW: Master Swift design patterns with my latest book! >>

< Previous: Debugging with breakpoints   Next: Wrap up >

View debugging

The last debugging technique I want to look at is view debugging, because this is relatively new so developers aren't really using it much yet. View debugging used to be difficult to do, because you'd have a complicated view controller layout with buttons, labels, views inside views, and so on. If something wasn't showing, it was hard to know why.

Xcode can help you with two clever features. The first is called Show View Frames, and it's accessible under the Debug menu by choosing View Debugging > Show View Frames. If you have a complicated view layout (project 8 is a good example!), this option will draw lines around all your views so you can see exactly where they are.

The second feature is extraordinary, but I've only seen it used to good effect a couple of times. It's called Capture View Hierarchy, and when it's used your see your current view layout inside Xcode with thin gray lines around all the views. You might think this is just like Show View Frames, but it's cleverer than that!

If you click and drag inside the hierarchy display, you'll see you're actually viewing a 3D representation of your view, which means you can look behind the layers to see what else is there. The hierarchy automatically puts some depth between each of its views, so they appear to pop off the canvas as you rotate them. This debug mode is perfect for times when you know you've placed your view but for some reason can't see it – often you'll find the view is behind something else by accident.

Learn Swift faster!

Take your Swift learning to the next level: buy the Hacking with Swift e-book and get bonus material to help you learn faster!

< Previous: Debugging with breakpoints   Next: Wrap up >
Click here to visit the Hacking with Swift store >>