UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

How can you get started using Instruments?

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.

Listen on Apple Podcasts

TAKE YOUR SKILLS TO THE NEXT LEVEL If you like Hacking with Swift, you'll love Hacking with Swift+ – it's my premium service where you can learn advanced Swift and SwiftUI, functional programming, algorithms, and more. Plus it comes with stacks of benefits, including monthly live streams, downloadable projects, a 20% discount on all books, and free gifts!

Find out more

Sponsor Hacking with Swift and reach the world's largest Swift community!

BUY OUR BOOKS
Buy Pro Swift Buy Pro SwiftUI Buy Swift Design Patterns Buy Testing Swift Buy Hacking with iOS Buy Swift Coding Challenges Buy Swift on Sundays Volume One Buy Server-Side Swift Buy Advanced iOS Volume One Buy Advanced iOS Volume Two Buy Advanced iOS Volume Three Buy Hacking with watchOS Buy Hacking with tvOS Buy Hacking with macOS Buy Dive Into SpriteKit Buy Swift in Sixty Seconds Buy Objective-C for Swift Developers Buy Beyond Code

Was this page useful? Let us know!

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.