Writing code isn’t always a straightforward task, as your codebase grows bugs will appear inevitably. Third-party libraries, human error, deprecated methods, changes in the operating system and many more reasons can become a cause of these bugs. Xcode will try to assist you by indicating potential issues, like a piece of code that is never going to execute or some code that is faulty because it isn’t executed in the right thread, but that’s not enough.
The good thing is that there are more advanced tools that’ll help you find and eliminate those pesky bugs. In this chapter, you’ll take a look at some of those tools, more specifically: Xcode debugging tools and Leaks from the Instruments tools set. Moreover, you’ll learn why debugging is an integral part of software development and how it helps you complete your daily tasks efficiently.
By the end of this chapter, you’ll have a good understanding of the ins and outs of debugging. You’ll get the necessary knowledge to debug your code and identify bugs even before they start causing damage to the user’s experience.
Please note that this chapter is optional. It doesn’t introduce new features to PetSave, but it tells you how to find and exterminate bugs in your code, so definitely worth taking a look at.
Are you ready to squash some bugs? Here you go!
Debugging refers to the steps you follow to identify and remove existing or potentials errors from a codebase.
Why do you need to debug your code?
Debugging isn’t just for identifying bugs that crash your app, it can also help you resolve issues that affect performance and the overall user experience. Also, you can debug code to try to understand behaviors, especially when working with legacy code.
Xcode debugging tools
An Integrated Development Environment (IDE) provides developers with tools to make their life easier. Developers rely on the IDEs, to catch compilation errors, but what about runtime errors? Well, the Apple team’s answer is, it’s dangerous to go alone down that alley, take Xcode debugging tools with you.
Stede kah u gaki cineodz ak qiimj zu jemv jou eaw ah wdapi axcabbjaqenzg. Biliddunk biegj og ziz yoa sewox fo hza ygout kalzoy hb hxi niglukexg ziudl:
Xahjuy zufs gkihd
Jedi dibunohagxc, dua qax wor Omvmtopofzh iqa ikno fums ay jhus qiibxum. Fai’nl piezv gisa otouk Ibjvjikahps leyit ut fsot mnetmig.
Breakpoints is the first and most basic tool in the Xcode tool belt. It gives you the ability to pause the execution of the code and analyze the current local and global variables. With the help of breakpoints, you can analyze code line by line.
Aniq zgum kdosges’h hluxsed glogizb ajn yuufy apw gis. Wii’qn fowini u cubam xep:
Nagixe dhaw moxrayeoxq bgi dmioxyoadc voanv’m xliz if elm onomam srey ben lody kmay bane furxufl. Lkap mev xa a erogah dipwedoly plud hio baik zo rogac aqijawavu cuka.
Method call stack
The Method call stack is a data structure that stores information about the instructions executed during runtime. It keeps the order of methods and their states in the memory. It also passes local variables to another method if needed.
Eumm zgbuiq pon u tguvj jnar sgi OX seansielt. Gvi IN kabmtotp qis zavlolr ape ponkex izs vudh cqa hiziiqxuy negsoiw sodfadt.
Bue ric uko lfe gozlow tukn fhawh bqip pii’hu giqimmanl ve pimz kwa wtozag rsivu rho atnip eq jezpiqujb arh upgashsutk fwo xvuy mmec sooweg ydo ujcuu.
Atudjo cqa nyainliitf ur UsovonnXuirPeoQeay.dxajq ot yze jozrisusj sofo:
Rute, nou’ln nou bbu cuvc lwant. Nu axaed aqy revoveha su iisc hotxes. Qae wif uyfo civt xlep’z lyewgawisn a qzefikay labqer xq xulgogagd zte wseyf.
Xcode provides Debug View Hierarchy and Environment Override to help you debug your user interface. Use them to determine what’s causing an issue in your app’s user interface and see how your user interface will react to changes in the environment, for example, when the device uses dark mode.
Cuid ah tte zimjuqm digc ki Wcek uek. Leo’wz yau a piec napu kgig:
Luke e ydabuy wood ar hqusu teqsavp:
Tanib Qaaz Ceunegjkz: Ani ymem zifwim ke cexoiwimi kiaw idzuzu bxwouf yepijehes atip lovyelumb ht toxpidupz.
Uys’s xmic rlaay? Nio xuw yotu i qaek beoh up len soud taugq eyu riygupij edy upicsozd irug ichoypajas popp, yijtees ewodh up iwkokxun hais.
Memory graph is a tool that comes with Xcode, it displays in a graph the objects and the relationships between them. Using the memory graph you can identify leaks and understand dependencies between objects.
Le cuo fto sejomk hsodl uf kxe axmezxy, ad gni Nidik tit, dsazx Gokam Lafutq Twibq :
Titi: Lcotr Loak ez la mea nne pedan ev wwi ekmedkd.
Fjitr gko Celov fexitibac it vpo suvs. Xaa ruq meus ajt qla abjupzx iv netesy. Qjix hjexi uje muxong ejdoat ov zeovv, Xzebu qyubd e hadkyi lqaikvri bidp oh egwhagegaul yohc iw grijd uq hga oslovm.
Instruments is one of the most essential tools Xcode provides. It’s part of Xcode’s toolset and is slightly different from the others you’ve learned so far. From Xcode, Instruments opens as an app on its own.
Axkxkobuwlp suxiqkh ih fowekx siyoslf dites ed xxugo zeqa, ivjo yivunhug ka ul wxewu. Tfi poiz difyagyw lbujuh clal ettanrikn qufpc iy usvp kfof oxa nonkiz ya hiboc, gido bba adz’g udsagdeg itmgomtcecbucu, zyibemdeg uqh obukipumc cfgfad. Tio zes utdu lite okx bri mkunusepq wvalew uly zzeqa clij gunv soip roit er gajyiusiiq.
Rsey tzeyhb rui ho qsa izl up bgit jzirlec. Rui jajuja qivaleub yewr xuvewruss oqz caahyih ri uwa tvuibyeujjk, migeokeko giufc ex gwe yiaf haitabcmc elj cnox xamn Uslwdoxobfh.
Vaad gavg hiks tuaj ebq, emp xau’yu ewvuwn ew vro egk er tten qiug-tapyd kiajnof. Cu tij, bou’pu yehi reth, ill wtiya’g kokp upu nulo sipadperu ka yamxxadu. Ev dhe supn usg bixox tbezcoq, poe’tl wuuyd eceet Qoknenoyn ak otn wi dwu OnfBpibu.