|< What are the most common problems with debugging in iOS?||How can you get started using Instruments? >|
Recorded – watch the full episode on YouTube.
Apart from just using
po and breakpoints, what other debugging tools do you rely on heavily?
Carola Nitz: I mean the UIView debugging tool is for me really, really important especially when you have layout issues. You get to see so much more about what is wrong. You can focus in on the constraints for example. And then you notice like, "Oh, this is an ambiguous constraint and I didn't even notice that when I laid out my code." So for me doing a lot of UI work, that is definitely a very important tool.
Paul Hudson: Right, because that's where you can pull apart your UI in 3D, you can spin it around, you can filter by depth and layers and you can dig and say, “What do you have for constraints?” Or, “why are you opaque?” And it really gives you an idea of what's actually happening with your finished code.
"I don't think a lot of people realize you get the addresses in the view debugger for a certain view. If you take that, if you cast that address to whatever object it is let's say UIView, you can actually on the fly change properties."
Carola Nitz: Not only that, actually I don't think a lot of people realize you get the addresses in the view debugger for a certain view. If you take that, if you cast that address to whatever object it is let's say
UIView, you can actually change properties on the fly. So sometimes what I do is change the background color of something just to make sure it’s actually visible, and once you hit resume again it changes the background color and you can manipulate code that way.
Paul Hudson: So there you go. It sounds like an immediate win: if you're doing
po already to print things out, use the view debugger, find the address for the view you want, and then
po that – and actually then modify it and see it change live.
Now as a related question to that, this is a random one but I'm curious: when you're thinking to yourself is this view visible you give it background color, we all give our background color which background color do you choose?
Carola Nitz: I use red. I really use red.
Paul Hudson: Yes, I use red as well – good!
Carola Nitz: Why are people using like blue, purple or green?
Paul Hudson: Those weird people over there are definitely using different colors than red. But yeah, I think it is mostly red.
Carola Nitz: I don't know why, it's just so easy.
Paul Hudson: It just stands out as a big warning sign this view is what is it doing over there? It shouldn't be over there it should be over here or bigger or behind something else. And yeah, red just screams problems to me I guess.
Carola Nitz: Yeah, same.
This transcript was recorded as part of Swiftly Speaking. You can watch the full original episode on YouTube, or subscribe to the audio version on Apple Podcasts.
SPONSORED Fernando's book will guide you in fixing bugs in three real, open-source, downloadable apps from the App Store. Learn applied programming fundamentals by refactoring real code from published apps. Hacking with Swift readers get a $10 discount!
Link copied to your pasteboard.