< What are the core tools for debugging iOS apps? | What is the best way to approach debugging a bigger iOS problem? > |
Recorded – watch the full episode on YouTube.
With instruments being quite so daunting what advice would you have to help someone put a toe into Instruments in an easier way?
Carola Nitz: I have to admit I don’t use Instruments super often – it's only when I have really gnarly problems like for example when we see a very high memory increase. What I usually do is, because I also forget sometimes how everything works, I'm trying to look at WWDC videos where people explain how to use it. Or sometimes you have great blog posts as well where they're just like breaking everything down for you how to best use it. Or sometimes if you have a good colleague who knows about these things involve them, work together on that.
Paul Hudson: Well I guess you're lucky there because at Netflix you have Jordanna, you now have Adam Bell as well and I'm sure some other great engineers. You've got an A-Team around you to help you learn and find and fix things – presumably you can ask them a lot of questions.
“What I usually do is, because I also forget sometimes how everything works, I'm trying to look at WWDC videos where people explain how to use it.”
Carola Nitz: Yes, absolutely. I actually lean on my colleagues, and they lean on me – I guess that's what a team is for, right?
Paul Hudson: So often folks like Prathamesh who is doing po
or similar – that mostly works. You go and have this code that isn't quite right, such as a name
variable,so you pause the program, go to the terminal and type po name
or something like that. And Swift will say, "There is no name
– what do you mean name
?” And you're like, "No, no, it's right there – I can see it, why can't you see it?" And Swift will deny all knowledge of there being a name
. When you hit that kind of wall – and sadly still do quite often – where do you go next?
Carola Nitz: I mean honestly I also use a lot of po
and for something like this I go back to print debugging sometimes. If it's just too hard to figure out what's wrong with my debugging yeah, print debugging is the way that I solve this. But sometimes if it's just a property that’s missing it's usually just because my debugger doesn't know what kind of object I have there in the first place. So then I do some type casting and then I can call that method because you can’t always just stop your program and add another print()
command in, especially if you're trying to debug a really hard edge case.
"I actually do that when I run through a certain code path very often and I need to follow what kind of input that method got over time, then I definitely use it quite often. But other than that I use
po
a lot."
Paul Hudson: So how often do you fall back on just literally scattering print()
statements around? Because you know most if not all of Apple's debugging tools, but how often do you literally say, “right I've exhausted everything now I'm just going to put print("OMG")
here and see what comes out?”
Carola Nitz: I actually do that when I run through a certain code path very often and I need to follow what kind of input that method got over time – then I definitely use it quite often. But other than that I use po
a lot.
Paul Hudson: I actually made a simple Xcode source editor extension that you press button and it adds print("I am in X named method")
in every method you have in your class and then you can press a button to remove them all in one pass as well. If I had any time on my hands, I'd make it also print a message when you leave the method – something like print("Entering method A")
then defer { print("Leaving method A") }
. But I have no time, Carola – you know what it's like!
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 Alex is the iOS & Mac developer’s ultimate AI assistant. It integrates with Xcode, offering a best-in-class Swift coding agent. Generate modern SwiftUI from images. Fast-apply suggestions from Claude 3.5 Sonnet, o3-mini, and DeepSeek R1. Autofix Swift 6 errors and warnings. And so much more. Start your 7-day free trial today!
Sponsor Hacking with Swift and reach the world's largest Swift community!
Link copied to your pasteboard.