0:00:00welcome to under the radar a show about
0:00:02independent iOS app development I'm
0:00:04Marco Arment and I'm David Smith under
0:00:07the radar is never longer than 30
0:00:08minutes so let's get started so today we
0:00:12wanted to dive into everybody's favorite
0:00:15pastime as a developer and that is
0:00:18debugging it is a topic that I think we
0:00:22probably it's fun of weird in some ways
0:00:25I think I probably spend at least half
0:00:28if not a majority of my time in
0:00:30development debugging code that I ride
0:00:32yet in most of my like actual formal
0:00:36preparation for being a software
0:00:38engineer there was very very little time
0:00:40and attention spent on it like almost
0:00:42all of my classes and things are all
0:00:43about focused on the actual development
0:00:46in the architecture side of things
0:00:48whereas the reality is we spend most of
0:00:50our time you know fixing the problems
0:00:52and issues that arise in our apps and
0:00:55this year these can range from all kinds
0:00:57of you know to different levels there's
0:00:59the kind of while you're developing
0:01:01debugging process where you know you
0:01:03write some code you you know hit build
0:01:05and run and you see if it works and if
0:01:08it doesn't you try and work out why
0:01:09there's the you know the act the sort of
0:01:12more subtle something happens every now
0:01:15and then and you're not really sure why
0:01:16and you try and track that down and then
0:01:19there's the you know you getting crash
0:01:21reports or bug reports from customers in
0:01:23the field and then you have to try and
0:01:25track those down which is even more
0:01:27exciting and challenging but in all of
0:01:31them I think there is an element of you
0:01:34know debugging is essentially you have
0:01:36you sort of identify that there's some
0:01:38problem you then try and reproduce that
0:01:42problem in a way that you can then
0:01:44observe that problem then you try and
0:01:48isolate where and the actual you know
0:01:50program that is happening and then you
0:01:52can try and fix it and you kind of go
0:01:54through this cycle of you know you
0:01:55identify it you we produce it you
0:02:00isolate it and then you can fix it and
0:02:01you kind of cycle through that or at
0:02:03least is the process that I tend to take
0:02:04because if I don't go through each of
0:02:07those steps I find that it's very hard
0:02:09to actually make progress I mean if you
0:02:10can't you know some bugs really are by
0:02:13their nature
0:02:13kind of hard to reproduce and if that's
0:02:15the case like you know that's still a
0:02:17bug and it's so problematic but you know
0:02:20if I get a bug report that I can't
0:02:22reproduce in any way
0:02:23it's just as the same in some ways is
0:02:25not having that bug report in the first
0:02:27place because I can't do anything with
0:02:28that information if I can't reproduce it
0:02:30so you know my first step is always
0:02:32let's reproduce this and then you know
0:02:34this try and find the part of code and I
0:02:36think having been a professional
0:02:39developer for enough years now like I
0:02:41feel like I have a better sort of sense
0:02:44for where the bugs might be hiding you
0:02:46know it's like we I've seen every you
0:02:49know not every bug but I've seen a lot
0:02:50of Fugs before and you kind of get this
0:02:52sense of like huh you know this is it
0:02:54this looks like this is a you know and
0:02:57off by one error this is this looks like
0:02:59this is a in you know cache and
0:03:01validation error this looks like you
0:03:03know I'm writing something incorrectly
0:03:04here or I forgot a case in a switch
0:03:07statement like you kind of get this
0:03:08feeling for it and then you can kind of
0:03:10go running around trying to find it and
0:03:12of course there's also I guess the other
0:03:13kind of debugging which is even super
0:03:15fun which is where there's a bug in the
0:03:17OS that you you know where your code is
0:03:21all doing the right thing but then
0:03:23you're getting weird results from the OS
0:03:26and so that's an even more fun you know
0:03:28fun line of debugging where you kind of
0:03:30get the sense of at a certain you keep
0:03:32going down and farther and farther down
0:03:33the rabbit hole until eventually you're
0:03:35like hit a brick wall at the end of it
0:03:36you're like alright well I guess I file
0:03:39a bug yeah and that's you know it's it's
0:03:43often easy for us to jump to well this
0:03:47must be a bug in the OS or my favorite
0:03:49one this must be a bug in the compiler
0:03:50or something like that when we can't
0:03:53figure it out that is for the vast
0:03:56majority of bugs that we face as
0:03:58programmers that is almost never the
0:04:00case it like first of all you are
0:04:03unlikely to ever have a bug in the
0:04:04compiler actually affect you and you
0:04:07know as you go up the stack of you know
0:04:09things that you're relying on like the
0:04:11OS does have bugs libraries that you're
0:04:14using will have bugs but if you run into
0:04:17something in your app that that seems
0:04:20like a bug and you were tempted to blame
0:04:22the OS or a library or something like
0:04:25that really make sure
0:04:27that you can't figure out that it's your
0:04:29bug first because chances are very very
0:04:32good it's probably your bug the vast
0:04:35majority of the time of those cases it
0:04:37will really be your bug it's only a
0:04:39question of whether you can find it but
0:04:40don't just say oh well it's a bug in the
0:04:42OS I guess I got a s I'll just deal with
0:04:44this or move on or yell at them really
0:04:47make sure it's not your bug first
0:04:49because again the odds are strongly in
0:04:51favor of it being yours yeah and then
0:04:54because the reality is like most of our
0:04:56time at least in these in my experience
0:04:57like dealing with bugs I it's almost
0:05:00always something I forgot to do or a
0:05:03case that I forgot to consider when I'm
0:05:05just originally doing it like in not
0:05:08necessarily out of like laziness even
0:05:11like sometimes it's that you know
0:05:12sometimes you have the always classic
0:05:13like you know you see an example where
0:05:16it's like if error doesn't equal nil
0:05:18then do something with it
0:05:20it's like and then if you don't actually
0:05:22do anything when eventually you do run
0:05:24into the situation where the error is
0:05:25not nil then all of a sudden things
0:05:27break and you know that there's that
0:05:28kind of laziness but more often it's
0:05:30just like you forgot to do something and
0:05:32then it comes back to bite you and I
0:05:34feel like the what is it I think there
0:05:37was a you know maybe maybe have been an
0:05:40xkcd cartoon about this where it's sort
0:05:42of that the stages of debugging where
0:05:44you go from like it's like oh it's you
0:05:47know you get a bug report you know like
0:05:48oh no that can't be right I'm sure this
0:05:50is I'm sure my code is good and then you
0:05:51kind of like no it's actually it's
0:05:53actually broken and then you go to the
0:05:54like how did this ever work yeah okay
0:05:57how on earth did this even work we you
0:05:59you amazing how when you look back at
0:06:02your own code you know this is think
0:06:04code that you wrote with your own you
0:06:06know your own hands on a keyboard you
0:06:07put this into the empty into the into
0:06:09Xcode you come back and look at your
0:06:11like how when earth what am i doing like
0:06:13and I feel like that is the hardest part
0:06:15and or why do bucking is so hard is it's
0:06:18you have to recreate all of this sort of
0:06:22state and information that went into the
0:06:24creation of the code hold that in your
0:06:26mind and then run it through a scenario
0:06:29that's happening you know and to then
0:06:31see why it's doing something weird and
0:06:33very often I find like the hardest thing
0:06:35is to try and understand even what the
0:06:37code is trying to do in the first place
0:06:39or like why there's this weird exception
0:06:41you know that was introduced there you
0:06:43know your yours or you know decades ago
0:06:46and you're like huh I wonder why I did
0:06:48that I don't know anymore
0:06:50and that's you know makes debugging
0:06:51really really hard yeah and this is you
0:06:54know it's also a major argument for
0:06:56keeping things simple and not that
0:06:59clever in the first place and yeah as we
0:07:02talked about I think a while ago now you
0:07:04know like I try to avoid overly clever
0:07:06code Styles things like you know using
0:07:09using really dense short hands or really
0:07:12clever mechanics you know things like
0:07:16generics in like you know Swift like
0:07:18that kind of thing I'm like we you kind
0:07:19of use like overly clever complex
0:07:22language features or constructs where it
0:07:26looks really cool and you feel really
0:07:27smart when you do it but when you have
0:07:29to come back and debug code you know in
0:07:32six months and you have totally
0:07:34forgotten what led you to to write that
0:07:37and you and you've forgotten the
0:07:38cleverness behind it and you have to
0:07:40figure it out by looking at it or or you
0:07:42know figuring out by by its effects it's
0:07:44often very very hard to do that and you
0:07:46know like you know you you often as a
0:07:49programmer you you might eventually hear
0:07:51the wisdom of like write code for
0:07:54someone else to read but but really what
0:07:56you should be doing is writing code for
0:07:58yourself in three weeks to read because
0:08:01you will have probably forgotten by then
0:08:03why you did what you did so if you keep
0:08:06things simple from the beginning and not
0:08:08be too overly clever with the way your
0:08:10right things and and make things you
0:08:12know straightforward to read and to you
0:08:15know kind of self document then you will
0:08:17be doing yourself a huge favor
0:08:19documentation you know separate
0:08:21documentation can help with some of
0:08:23these things but I found in practice
0:08:25that maybe it's just me I don't document
0:08:27things that well I try to just write
0:08:29things that are that are obvious when
0:08:31you look at them and that that you know
0:08:32just have good names and straightforward
0:08:34approaches and that tends to work very
0:08:37well and you know that can never be out
0:08:38of date because it's the code itself and
0:08:41then for for minimizing bugs to begin
0:08:45with I think it's it's again very
0:08:47important not to be too clever and and
0:08:49to realize you know for me many of my
0:08:52bugs come from
0:08:54quick workarounds or quick hacks that I
0:08:57do when I encounter some other bug and
0:09:00and so one great example of this then
0:09:03that I'm sure many iOS programmers face
0:09:05is whenever you are doing something in
0:09:09in like a launch loop or or in in a UI
0:09:13you know response or something and
0:09:15there's some weird behavior that or some
0:09:18weird precondition that you can't quite
0:09:20accommodate in a straightforward way so
0:09:23you just dispatch async to the next run
0:09:26loop of the main queue and you say all
0:09:28right dispatch async got to make you do
0:09:30this thing on the next run and that's a
0:09:33really nice quick way to to avoid a lot
0:09:36of a lot of like you know weird
0:09:38complexity or obvious bugs as you're
0:09:41developing but I have found in almost
0:09:43every case that using a dispatch async
0:09:47is almost always a bad idea like when
0:09:50you're just like I'm deferring work till
0:09:52the till later on the main queue or
0:09:53something like obviously there are uses
0:09:55where it where it's fine but like what
0:09:57if that's your approach to solve a
0:09:58problem then you get into concurrency
0:10:01bugs
0:10:02and weird weird conditions there that
0:10:05are really hard to fix and diagnose and
0:10:09reproduce and it again it's like one of
0:10:13those areas where it seems like a clever
0:10:16thing when you're writing it and and in
0:10:19the case of like bug avoidance like it
0:10:21seems like oh this will be a quick fix
0:10:22for this weird little bug I'll just wrap
0:10:24it in dispatch async and that will that
0:10:26will fix the problem but then you
0:10:28introduce all these weird other problems
0:10:31that might be non-obvious and those
0:10:33those become very hard to debug so in
0:10:38addition to keeping code simple as you
0:10:40write it for the purposes of debugging I
0:10:42also would strongly recommend avoiding
0:10:45concurrency if you can and avoiding
0:10:47playing with with threads and queues
0:10:50when when not necessary or when not
0:10:53warranted because I feel like what
0:10:55you're doing there I mean I'm very
0:10:56guilty of that thing there I've done the
0:10:59you know dispatch async fix probably a
0:11:02hundred times 200 times my career like
0:11:05all the time and I cannot I cannot
0:11:06overstate how men
0:11:08bugs that I've had to fix end up being a
0:11:11poorly used dispatch async yeah I think
0:11:14what the reality is what you're doing
0:11:16and this is maybe a maturity thing but
0:11:19it's the quiet sea understanding that
0:11:20like when I do that now I understand
0:11:22that I'm not fixing the problem I'm
0:11:24changing the bug from whatever it is say
0:11:27see I said a bug that happens you know
0:11:29one out of every hundred times the app
0:11:31is of the app runs and you know that's a
0:11:34problem you know 1% of users are hitting
0:11:35this issue I wrap it in dispatch async
0:11:37what I'm doing is not removing that
0:11:40problem what I'm doing is changing it
0:11:42into a like 1 in 10,000 bug which is
0:11:45better but also incredibly difficult now
0:11:48to actually like properly fix and
0:11:51diagnose and reproduce etc etc like it
0:11:54is the kind of fix where it isn't
0:11:57actually solving it it's just making it
0:11:58less likely which sometimes you know
0:12:00pragmatically I've you know there I'm
0:12:02sure there are many places in you know
0:12:03my shipping apps where I have that and
0:12:05it's just one it's like a conscious
0:12:06choice that you're just like well the
0:12:08actual fix is too hard or would require
0:12:11a massive refactoring or some kind of
0:12:13you know thing where you can make this
0:12:15trade-off in choice and you say you know
0:12:16like I'm just gonna fix this by patching
0:12:18it and I know that what I'm doing is
0:12:20gonna cause a problem for me down the
0:12:22road I know that I'm you know there is
0:12:24this bug is hasn't magically disappeared
0:12:26as a result of this but like it's a
0:12:28conscious choice and that's a balance
0:12:30but yeah ultimately you know the most
0:12:34when you're writing the code you're kind
0:12:35of trying to do your future self a favor
0:12:36as much as you can because I think one
0:12:39of the things that I struggle with - and
0:12:40I'm writing code is the realization that
0:12:42I all of these things that seem obvious
0:12:45to me when I'm writing the code because
0:12:48I'm in a mindset where I'm focused
0:12:50entirely on whatever the solving this
0:12:51problem is like there's all these things
0:12:52that just seem obvious like of course
0:12:54you know like this is the way this works
0:12:56you know that's why this is set up this
0:12:58way this value will you know will always
0:13:00transform from this to this like there's
0:13:02all these things that seem obvious and
0:13:03then in the future they're entirely
0:13:06non-obvious
0:13:07and the didn't think the biggest
0:13:10difficulty I have with things like
0:13:11documentation is that it's it kind of
0:13:15impossible to know what your future self
0:13:17is going to want to know
0:13:20because everything seems obvious and
0:13:23kind of trivial at in the present and so
0:13:27like I think I'm kind of like you I'd
0:13:29tend to only document code in my apps
0:13:31that where I'm doing something that is
0:13:33clearly weird or like strange you know
0:13:37where you have some kind of magic number
0:13:39it's you have to introduce into
0:13:41something worth like I know why am i
0:13:43multiplying this value by one point six
0:13:45three two like there's a reason for that
0:13:47and if there is like you know that's the
0:13:49kind of thing that you write down but
0:13:51otherwise you end up with like writing
0:13:52your program twice if you're overly
0:13:54documenting it so as you know as much as
0:13:56when I'm debugging I kind of wish my
0:13:58past self had written all this stuff
0:14:00down
0:14:00the reality is my past I wouldn't
0:14:03actually know what I need to know right
0:14:04now because if they did they could have
0:14:06just write in you know made the code
0:14:07more obvious or clear in the first place
0:14:09probably or these that's what I tell
0:14:11myself we respond to this week by
0:14:15Pingdom start monitoring your websites
0:14:17in servers today at Pingdom comm slash
0:14:20radar you get a 14-day free trial I'm
0:14:22gonna use code radar at checkout you got
0:14:2420% off your first invoice Pingdom is a
0:14:27wonderful monitoring service they are
0:14:30focused on making the web faster and
0:14:32more reliable for everyone who has a
0:14:34site because they offer powerful easy to
0:14:37use monitoring tools and services so if
0:14:39you're a premium user you can monitor
0:14:41the availability and performance of your
0:14:42servers your databases or your website
0:14:45and it's so easy to do they test from
0:14:48more than 70 global test servers and
0:14:50they can they can emulate visits to your
0:14:52site as often as every minute and they
0:14:54can do cool things like cookies and
0:14:56logins and everything else too because
0:14:57you know these days websites are
0:14:59becoming more and more sophisticated and
0:15:00very often include multiple different
0:15:02parts with several different
0:15:04dependencies maybe you dependent on
0:15:05external service or maybe only the login
0:15:07screen does this one thing in your code
0:15:09and you need to check all these things
0:15:11and you can do all that with Pingdom
0:15:13with and loads more in addition to that
0:15:15too they can make it possible to monitor
0:15:17the availability of all these key
0:15:18interactions people have with your site
0:15:20because you know a lot of times it's
0:15:22more complex than your site is up or
0:15:24your site is down so stuff breaks on the
0:15:27internet all the time Pingdom knows this
0:15:29they detect around 13 million outages a
0:15:31month
0:15:32so regardless of whether you have a
0:15:33small website or you're managing a whole
0:15:35infrastructure it is very important to
0:15:37monitor the availability and performance
0:15:39and all in Pingdom when it goes down
0:15:41they alert you in any way you want you
0:15:44can have text messages you can have push
0:15:46notifications emails it's so
0:15:48configurable we've even used it in the
0:15:50past to monitor other people's websites
0:15:52like David and I have both independently
0:15:54used it to monitor the WDC page for
0:15:57changes and like in the past when it was
0:15:59really important to know when WTC
0:16:01tickets went on sale I've used Pingdom
0:16:02for a very long time
0:16:03highly recommended check it out today
0:16:05and you will be the first to know when
0:16:07your site is down or being too slow so
0:16:10go to Pingdom comm slash radar for a
0:16:1314-day free trial and use code radar to
0:16:16get 20% off your first invoice thank you
0:16:19very much to Pingdom for their support
0:16:20of this show and relay FM so the other
0:16:24thing is probably worth diving into a
0:16:25little bit too is the way in which we
0:16:27actually do debugging because I maybe
0:16:31it's you know maybe it's a shocking real
0:16:33revelation but I am I believe what is
0:16:35technically called a caveman debugger
0:16:37the printf debugging I do all of my
0:16:41debugging using you know NSLog yep in
0:16:46the console which I you know I think is
0:16:47often disparagingly referred to as
0:16:49caveman debugging which is fine I'm sure
0:16:51there are better ways to do that and I
0:16:53mean every now and then I'll go to WDC
0:16:55session where they're talking about all
0:16:57the crazy things you can do in you know
0:16:59in Xcode where you can set conditional
0:17:01breakpoints and you know all this kind
0:17:03of really clever stuff and in the end
0:17:05what I always do is just INF just NS
0:17:07logging tons of data to the console
0:17:10because it's it's one of those things
0:17:13where most of what debugging is trying
0:17:15to do is it's like you're trying to
0:17:17unwind the state machine that is your
0:17:19app or you're trying to work out we know
0:17:21it's like your app is in this probably
0:17:23you're in a good state then something
0:17:25happens and you're in a bad state like
0:17:27that is you know at a very high level
0:17:28that is what a bug is and what you're
0:17:31trying to do is identify that we know
0:17:33what point it's going from that good
0:17:36state to that bad state like what is
0:17:37happening there and you know I mean I've
0:17:40been professionally developing for 17
0:17:43years now or something and I still like
0:17:44that the most
0:17:45effective and powerful tool is just n s
0:17:47logs everywhere and you get kind of good
0:17:51at it like I'm I can identify and find
0:17:53things fairly quickly this way because
0:17:55you kind of get the sense of you know
0:17:56you're a you're trying to isolate where
0:17:58in the code it's happening and so you'll
0:18:00end up putting ns logs you know in
0:18:02different in different parts of your app
0:18:04that you think might be part of it and
0:18:05trying to work out which ones getting
0:18:07you know which code is getting hit when
0:18:09you when you do it and then something
0:18:12that I also find really helpful is when
0:18:14I take I format my NS logs as tab
0:18:19delimited text so like often will have
0:18:22like several variables that I'm trying
0:18:23to observe and watch and I NS log those
0:18:27as you know a tab delimited set of
0:18:30strings because then I can take the
0:18:31output from the console and I can copy
0:18:33paste that into Excel and it'll put it
0:18:35into columns for me that's interesting
0:18:38and you can then you know you can take
0:18:41that data and then look at it over
0:18:43multiple runs and you can start you know
0:18:44it's a way to actually make the day and
0:18:46make it into something that's useful and
0:18:47you know like at least for me in the way
0:18:51that my mind works that's how I debug
0:18:52the best is when I'm taking the state
0:18:54I'm taking something out of the console
0:18:55looking at it often in Excel and it
0:18:58would kind of fall finding the pattern
0:18:59finding the thing and then I can
0:19:01actually go and fix it and like I don't
0:19:05know if that works for me
0:19:06and you know I I sometimes I feel bad
0:19:10about it I think they have all these
0:19:11really powerful and clever tools but the
0:19:14reality is I think the hardest part too
0:19:16is that so much of these this kind of so
0:19:19much of debugging is like the hardest
0:19:20part is often the reproduction part and
0:19:23getting everything like it's hard to
0:19:26observe these issues sometimes and so
0:19:28like the nice thing about a console.log
0:19:29is that you can have those running
0:19:32without being attached to the debug
0:19:34server for example like you can have
0:19:37that you know you can you can create
0:19:39these situations where these things
0:19:40happen sometimes in like sometimes it
0:19:42gets really awkward to have your a to
0:19:44have your app attach the debugger
0:19:46sometimes when it is attached the
0:19:48debugger the app goes the bug goes away
0:19:49like there's lots of weird situations in
0:19:52issue square NSLog debugging is the best
0:19:55but I'm very aware that by doing it that
0:19:58way I am
0:19:59you know not taking advantage of more
0:20:00sophisticated tools but I know for
0:20:02myself like that's what works yeah I
0:20:05mean and it there's also there's lots of
0:20:07different kinds of bugs and and you know
0:20:09a lot of these different methods are
0:20:11more or less suitable to different ones
0:20:13like you know for example NS log
0:20:14debugging which I do a lot myself is
0:20:18it's it's not necessarily the best
0:20:20option if you have like like I'd like
0:20:24kind of nitty-gritty like code level bug
0:20:25that this function isn't always
0:20:26returning the right value like for that
0:20:28I prefer to use conditional breakpoints
0:20:29so I can see like you know whenever this
0:20:31value is something out of whack stop
0:20:33here and then I will inspect the stuff
0:20:34around it but you know and it's log
0:20:37debugging is a lot more helpful for
0:20:39things like you know larger systems
0:20:42interacting with each other many kind of
0:20:44you know large operation the concurrency
0:20:47things were like you're not really sure
0:20:48where the bugs might be but you kind of
0:20:50want to get a good idea of of what is
0:20:53going on in the system it's also NSLog
0:20:55debugging is also very very helpful in
0:20:57situations in which the debugger itself
0:21:00is impractically slow to do things so a
0:21:04lot of swift context this is the case
0:21:06from what I've heard it's also very much
0:21:08the case when you're debugging on device
0:21:10on the watch because like then like the
0:21:13round-trip between your computer running
0:21:15Xcode and the phone and the slow watch
0:21:18hardware like trying to try to break
0:21:19watch apps
0:21:20you know like with breakpoints and
0:21:22inspect local variables around and you
0:21:24know running things in the in the debug
0:21:26command line is so slow on the like when
0:21:29doing things on the watch that sometimes
0:21:31it's better off to just do something you
0:21:32know doot-doot-doot a different way do
0:21:34printf debugging or whatever else for me
0:21:36it's also I also debug very differently
0:21:38if I'm looking at a crash report versus
0:21:41some kind of behavior in the app that
0:21:43I'm catching live it's it's very
0:21:45important to to look in iTunes Connect
0:21:49and to look at the or a you know rather
0:21:51I guess now it's in the organizer in
0:21:52Xcode to look at the crash report that
0:21:56Apple's getting for you you know look at
0:21:58look at what's being gathered there
0:21:59there's a whole lot of different
0:22:01problems that your app can have in the
0:22:03wild and the fact that we can get our
0:22:05apps it's that we can get our crash
0:22:07reports basically all the time from
0:22:09Apple that like whenever an app crashes
0:22:11we get notified
0:22:12about that that's pretty awesome and of
0:22:14course also lots of different other
0:22:15services as well but there are some
0:22:17types of crashes that only apples crash
0:22:20logs will generally reliably be able to
0:22:22report to you that includes things like
0:22:24if i OS kills your app for some reason
0:22:27that isn't necessarily a crash but if
0:22:30your app is getting killed in the
0:22:30background or something or if your
0:22:32extensions are getting killed
0:22:34then that's things that iOS can can
0:22:36provide very useful feedback to if you
0:22:38look for it and that's all in the Xcode
0:22:40organizer and one of the things I can
0:22:42recommend highly is look at those and a
0:22:46lot of times the organizer won't tell
0:22:47you like if you get like in my I was
0:22:50just spending a lot of time debugging
0:22:51crashes and my today widget or my widget
0:22:53I guess and if you look at just the
0:22:56crash log it's not very helpful in the
0:22:58organizer but if you right-click and
0:23:01show and finder on that crash and you
0:23:03dive into the bundle and you can get the
0:23:05raw crash logs that are inside of that
0:23:07bundle when you look at the raw logs you
0:23:09can get a termination code and a lot of
0:23:11times that is springboard telling you
0:23:13something and there's a great technical
0:23:15note tn 21:51 understanding and
0:23:18analyzing application crash reports and
0:23:20this tells you all the crazy codes that
0:23:23your app might be killed with so one of
0:23:25the things is that I was facing is I was
0:23:27my extension was accessing the sequel
0:23:30Lite database in the shared app group
0:23:32container I don't recommend doing this
0:23:34now but now I know better
0:23:37but if you are accessing an SQLite
0:23:39database in a shared container in an
0:23:41extension at the time that the OS
0:23:43suspends you it will kill your app with
0:23:46a certain code that says deadlock in hex
0:23:48and if you didn't look at this document
0:23:50and if you didn't find that crash report
0:23:52and find that code and if you didn't
0:23:54then look at this document to see that
0:23:56what that means what it tells you right
0:23:57here
0:23:58it's un terminated by the US cause it
0:23:59held on to a file lock or sequel like
0:24:01database during suspension and I didn't
0:24:04like you know and before I found all
0:24:06this out I just didn't know why my
0:24:08extension just kept crashing for
0:24:10everybody and people kept reporting
0:24:11things like hey your app is crashing in
0:24:13the background for some reason getting
0:24:14all these logs on my phone what's going
0:24:15on iOS tells you these things like it's
0:24:18telling you useful information here and
0:24:19so if you if you look at those crash
0:24:23logs in the Xcode organizer and if you
0:24:25look up what these
0:24:26for you know termination codes mean
0:24:27you'll probably find out something
0:24:29useful and and this is all like and and
0:24:32we have wonderful things like if you're
0:24:34kind of wondering whether you fixed a
0:24:36rare crash or not you can look at the
0:24:38analytics section of iTunes Connect and
0:24:40it will graph for you how many crashes
0:24:43per day your app is having and you can
0:24:45cut and it marks on the graph where your
0:24:48updates occur so you can say oh look
0:24:49when when this update was released the
0:24:53crashes dropped by half so the thing I
0:24:55fixed I probably fit the thing I think I
0:24:58fixed I probably did fix there's all
0:25:00sorts of useful things you can get from
0:25:02crash logs and things of that and and
0:25:04one of the reasons why I do also as I
0:25:07said earlier kind of recommend against
0:25:09unnecessary use of dispatch async is
0:25:11because that makes your crash logs less
0:25:13useful to you because it it usually the
0:25:16crash logs will not report where the
0:25:19block was dispatched from some of the
0:25:22more advanced ones like hockey a try to
0:25:24do this and they have mixed degrees of
0:25:26success in my experience and so if your
0:25:29code is simpler than any crash log you
0:25:32get will also be more useful to you yeah
0:25:35if you crash logs are definitely like a
0:25:38great source for us so much of this
0:25:40stuff and I feel like in general I will
0:25:42say that Xcode as much as I don't use
0:25:45all of its tools like some of this stuff
0:25:46that you're talking about if going into
0:25:48the organizer like there's some really
0:25:49useful you need tools that we have at
0:25:53our head at our you know sort of at our
0:25:55disposal to be tracking some of this
0:25:56stuff down now which I don't think we we
0:25:58had before I mean it makes me think even
0:26:00of one of the other tools that I use a
0:26:02lot in debugging in a strange way is
0:26:05version control sin specifically get
0:26:09blame is often incredibly helpful in
0:26:12trying to track down weird situations in
0:26:16in my apps beware you know code is doing
0:26:20something weird and I'm trying to work
0:26:21out why I structured it in the way I
0:26:23structured it and this is something that
0:26:24I love in Xcode where you can go into
0:26:26the top right where you go into the
0:26:28source control thing and you can do
0:26:29blame and it will show you all of you
0:26:32knows for every line of code in your app
0:26:34it'll show you which commits that line
0:26:36of code was introduced into your
0:26:39with and so you often will end up
0:26:41happening there it's like by using that
0:26:43view I can be a see like huh that's
0:26:44weird
0:26:45you know here's this one random line of
0:26:47code that is left over from an old
0:26:49version that everything else was updated
0:26:51or you know situations like that and you
0:26:54know Xcode is really and then you can
0:26:55not think if you double-click on it you
0:26:57know show you that commit and I'll show
0:26:58you the relevant how that you know how
0:27:00that file a line of how that how that
0:27:02file changed with that commit and that's
0:27:05another example of one of these little
0:27:06tools in Xcode where it's like it helps
0:27:08you understand what's going on in the
0:27:10same way that yeah like those that's a
0:27:12really great one I mean I love in their
0:27:13crash logs were you know that can help
0:27:15you take you right to where the crash
0:27:17happened rather than sitting there and
0:27:19you know trying to you know work out
0:27:21which we know is if this crash happened
0:27:24in this you know and this this file on
0:27:25this line number like well I mean that's
0:27:28useful but it's also much way more
0:27:30useful to just take me to that line
0:27:31number so there's definitely some great
0:27:33tools in Xcode I think make a lot of
0:27:35debugging a lot simpler and I'm very
0:27:37grateful for I would also say when
0:27:40you're when you're running your app and
0:27:41you're trying to figure out maybe maybe
0:27:42what's going on with a bug always watch
0:27:44that that pain in Xcode shows you the
0:27:47running CPU usage and memory of the app
0:27:50and of course you can go into
0:27:51instruments and get you know like a more
0:27:52fine-grained version of this but like
0:27:54yesterday there was this really tricky
0:27:55bug that I could not figure out that the
0:27:57app too started behaving really weirdly
0:27:58when loading episodes of a certain
0:28:01podcast and it like really weirdly and
0:28:03it would eventually disconnect from
0:28:05Xcode it was a massive massive weird bug
0:28:07and springboard crash and what led me to
0:28:10the solution was that I was I happen to
0:28:13be glancing at that pain that was
0:28:14showing me that the resource graphs in
0:28:16Xcode that would during one of the runs
0:28:18and I noticed that right before it
0:28:20crashed memory usage skyrocketed all the
0:28:23way up to like a gig and then everything
0:28:25freaked out and blew up and so then I
0:28:27was able to sit to say hey wait a minute
0:28:29that's unusual that stands out let me
0:28:32run it under the the allocations
0:28:33instrument run that can show you where
0:28:36all your memory is being used and I did
0:28:39I so I did that and found out figured
0:28:42out what the bug was within like a half
0:28:43hour after that this is a bug has been
0:28:44bothering me for weeks I couldn't figure
0:28:46it out and then within a half hour of
0:28:48noticing hey this thing is out of the
0:28:49ordinary on the memory meter here
0:28:51I had the fix so like you know use the
0:28:54tools that are available to you when we
0:28:57know when appropriate or just use NS log
0:28:59and printf debugging everywhere yeah and
0:29:02I mean what that you would you down
0:29:04there there was one thing that I will
0:29:05say that I love about debugging is that
0:29:07so often you get to the end and there's
0:29:09like a relatively straightforward
0:29:10solution that fixes the problem and like
0:29:13that is one of the greatest joys of
0:29:15being a soft software development when
0:29:16you like you think you see the problem
0:29:18you see the solution and you can
0:29:20implement it and like it's gone and this
0:29:22thing that was problematic and hurting
0:29:24your users is now just completely
0:29:26vanished and like that's like a great
0:29:28victory and I always love when that
0:29:29happens
0:29:30doesn't always happen but when it does
0:29:31it's absolutely awesome so it's the one
0:29:33reason I love debugging that's why we do
0:29:35all this right that that feeling and
0:29:37when it finally works we're like yes I
0:29:39love that feeling all right thanks
0:29:41everybody for listening this week and
0:29:43we'll talk to you next week bye