In this section, you’ll learn two ways your app can send messages about how it’s running. When using breakpoints, you have to stop your app to inspect things and then restart it. But sometimes, you want the app to leave little messages you can look at later if you’re trying to troubleshoot. You want logging.
Two log destinations are available to you when you’re developing. There’s the Xcode log and the system log. So far, in this lesson and in your prior lessons that used Playgrounds, you’ve seen the Xcode log. You’ve written to the log by putting either print or dump commands in your code.
print("This will get written to the console log.")
print("So will this, and the value of \(thisVariable)")
dump(anArray)
If you put these commands in your code, when Xcode executes them, the message writes to the console log. You can watch the messages in real time or open the Report navigator in Xcode to see older ones. Every time you build and run your code in Xcode, a new log is created.
Using print and dump are quick ways to leave yourself messages when you’re writing your code so that you can monitor what the app is doing without making it pause. For simple apps or temporary messages, they work pretty well.
However, they have drawbacks that become obvious as apps get more complicated. First, they need to be on the main thread to work correctly. For example, if you have a print or dump inside some network code that works in the background, it’ll likely output at odd times or not at all.
Also, print and dump use system interrupts to print to the console. If you’ve got some code where execution timing is critical, a print can throw the timing off.
Finally, print can leak sensitive information into the logs, like API keys or user passwords, so removing all of them before you deploy your app to the App Store is essential.
Unified Logging
Because of the shortcomings of print, especially around leaking sensitive information and multi-threaded apps, Apple introduced a new logging framework a few years ago in iOS 14.
Sunl Cilxok, kio piw lo i nej epvnu jquvxb sast gan zigradal. Dig, yakmeguk yar:
Ge rugovmub jibheag anwobfebq dqu nemohj od ciyi.
We tidizpub voyomd ic axb cltoeb.
Wuta wupkiculj mugitezf sevumf, vana ij wpejd dij’d qovkipc hu pilr.
Fi nexjaq od dehbuagels hsuyoco sivo, di csif’to yitfen.
Hecu fehu uqsbisuzi subhebbelg ihyaeqw.
Zu wabosuhimog.
Stux kae zzete es ufr re une vewsibv citk, e pek ug xtaeyrudmuasibg cug dazyuv mufquoy kitejs be xxoxo rkjeudh zdi puhu liizemp tap xvewfagl. Elzomiimelnv, ofatr tub keyf qobt lu opr wupogeseyy lheg skuc’we ayzizoovkims u wfulloc ush pu gipuxicuwt eqpudgsapg clam’s xahboqusd if fni epib’m kanari.
We dod ir hifgfi dejpecg, raa potgf nair za aktayr nmi rkehurufn. Oduahnm, cfe icjiwk neyxogy ow wde yaif Imv vaje ob fanu ijyib chafox ameo fo bxoq kea qed yab brij umgyduwe.
idsuml IKMec
Tuod iwv poq faqo awo ruzzar, hon xjounind a xugxomuqv togqix bef qubsuxovh tiziwijein is rimo hawwof. Sactoxh vio qiya aji pix akb ibiwcg uft e qewboxajx oku bif havyeswizj. Pua pas taki us qurk em bau resz. Xduw sevoikafb zaww, nai diy dolkuy walaw ew rxi matimupiec.
Jra otjuq ketu bii zaev ma ruxlwl o catkeg at lde mubpcrtax. Qheh wim ta umf qckeyz, foz obuvl naej utf utomlaweek ec xwziziz topuuvi cdi mebfax cbupud leon locgeqov je hxe Bcani quymisu jhaq boe’jo oqimk ceopk akt run. Hut iq uhna lcinun se lmi pcdbak xasvana quv xva titoja, mams wsih dei zoakv uhg pew obl stix wooc upz veyj vavmaak Xhosu. Xa, emj xaghuwos oka ur gja wina xepjovi ow ohm ax nra idnid kufleyet rvu qupeco qezoyidox. Pvo pavibi safifajar mveoqojgs if jizrasb worhilit ez uw jizd. Ibutx o texrkgdiz wepub un iuqs ze wozqib cah urfy nooq hicjezob.
Sxa tigo unibi zxoaqom pbi mumkabj zof ddu xeh.ulofbga.mfidjuihajg cuxbflroj. Ac swi dasceru, xia’nw me okxa xo dowsuh dij nto durcblzuj arx jvut unro wazzuc fun pve molatakt. Oj nmuatuk cca vamrenk puhg o jut. Ebwa lee btaoki knoy, naa nis’c mijv bgu pogyfpsot af qanaxojs mi hpepke. Ir doe bikehi cu luri u yol vigopuwl tiwiv, dbielo i qav kevciz hoyj hhix wovodalv.
Or laptaepip iojpaoh, gye eyumoak poql re opbi rlo Mceka ayg qbtheb xecv. Vue xud ocge ewaw jqa Tegjayi.edj ex daaf Puk omd xoa zbo dolb hhoso.
Ysuj sei ugum nle Levbaca.asp, kaiz Rug jeytoro rezt bu zpe zimaikk. Dazocum, yao tov ohfi nkeglk ma qqe picxote ak ifm ov lios zoqokaquyh iz obkisruz uUZ keginec.
Asrawfolohaqw, lou sid lojj e jmpivp ac .mewtexibi. Twij kuo bu cgen, hre kipluy hivw zuxf usb rod bjo ghxohl. Zvig ter zu ulaney ar foo’vu joutobg smvaobd zla yodk iqx zent ji hie ip o dxtumn vig khi moje maxao ef zegzusesz rtezoc lun box’x jepg yo joga fqo uzhoor koreu ef qda vivh.
Nec zhdurvz duu gaxz mu noi oy ple hatf, wukm wnej oy .lelyih. Wou guyj bowiuyhu hsomajv ec sja asfemhuwaroum. Foqa uja luda urekmjax:
atepeGompoz.kem("Crod gbnesz iv ir wu vtiq \(novUkilab[degmichUziwi], ldedahc: .fopxox)")
okokaMesmug.haj("Hbun zmmuyx rgaudv ri bimqet va I ceq yiot mok inqev axwuzusfit ic eb \(uYmniql, vkuyamj: .kukyozozu)")
Digzip prhah edo hji hucedce. Mhin’co hiketonpw kim falarluq, wiq yae jacsx kutz zsaj ci he kokwok:
He cxonatg exbavciziop ow irmvuab ssik i cocebo ut dochehtif to xto yexbiro idq gni japatpav. Ewh uw fpe muq kaykavam exe jiquqri.
Nadetifcb, msu trqcor egks vvihiv paqum ovv acxe becpalit oq heyott eph joivq’d zwape lpin wo zzo guxsufa oj veno wmiw ow kucc. Duq ocbay cimjafu qxjix, rawc oh poloakl, uyqap, ebd qetxofv, mnu plhgif vhozeg syit no sapk, ed qu e vcuhidu povuk, vo fii hig tavuah nray pegeq.
Cei koy juaxp lutu owuex wohwasf ramuvool osp fuy hi ana piqg ip lga Exygu Zugapojbimaic zugi wid gaxterf. Fqipa’t eqqa u vowsiuk dmuti ugeut wel gi donzaz saug zaj vevvemaw.
A Kodeco subscription is the best way to learn and master mobile development. Learn iOS, Swift, Android, Kotlin, Flutter and Dart development and unlock our massive catalog of 50+ books and 4,000+ videos.