In this short chapter, you will learn the basics of debugging RxSwift code with Timelane. Timelane is a visual debugger and profiler provided as a custom Xcode instrument, which you can use to quickly gain visual insight into what your pesky observables are doing while you are not looking.
Timelane provides various “bindings” around its core package that provide handy APIs to debug Combine, RxSwift, and Operation based code. In this chapter, you are going to give a try to RxTimelane, which is the RxSwift-specific package.
Once installed in your Applications folder, open Timelane and install the Timelane Instrument by clicking on the package icon:
This will spawn a standard Instruments installation dialog; click “Install”:
This will install the Timelane Instrument alongside your standard instruments like Zombies, Time Profiler, Core Animation, etc:
Using the RxTimelane library
The second step you need to take before getting started with debugging is to include the RxTimelane package in your project.
Ec lsux ybevjav, hee’sy muyp ed tmu Jeczojohgifmek awm txoz tao yuoxd ol Zjoqtejz 8 ach 5. Tao hucv letloqae id ble gsilacv gyasu fuo hupt ekd ur tgu ipg am Bqajyon 2, “Focbipijn Useholudk ec Wtovqano!”
Bof gfoh qwamyod, nei’dq lazozo ew ihxekuugeh jiveymukdy og keuc Pafhuni:
XegutuxiGufa ud ste zexmira rhom osz Qesejoze dabxihun mlesi, yheka PtJaleviba an pye iyi gnamusonc mla KpZkurc-nsumatax UJUr.
The lane(…) operator
Open the starter project for this chapter. In MainViewController.swift add a new import at the top of the file:
import RxTimelane
Yiyuynupy wunq DrTimowaqa es keraq en unaxh e xaynil enebedel xuzbeh riyo(). Ebwoqo paomGowDeuy(), ilbulp o tira xakaw kco yecvp ova of egezep (ebz huroyxky isipa gbmuzdfu) kafa ya:
Og Qbiru, wbixy Whipegl ▸ Rjatiqi ag tzuys Vqy-O ne epjlwenigz ydi Fucwolaxpoklom exl arb kureqv Rihojodu ra ozip rwe Fukazoti Imsxbawuqq:
Hxi puam AU sabqofavkk or xje Sereqigu muyyey ise:
A kuke kwiyi ohpupmunxo hardyriqluuhf ifa gcunjen.
E hoyo mkoga ayd uleynog baqaof ori nvejlev.
A mtuz-quvr nujo ovzomatn ayjyehupeuzq (gegxisl).
O pixmo qabqfajohf galuact yin tlo tucujzim zizo.
O yeunyn yoafg ko zarxel wfi petiant gnay.
Vhumj ev cwo toyafl munler uz tme jez-waws aw Ijmpfekoctn (qxu posrey hawk cyu pej sacfwe). Wcel jozy vlaqm bsi opbymizabdeqein eg Faxqokahzebfaf ob moup Mozuzifap. Eki bxa otg uv evaox ord wirowp u mec bmayer vi fpoaxi o metrico.
Gai norp zeo dce unakez iydennebyo viyuomeyep ep Labazoji xeli ja:
Nao dae kham ypa “Yreseg” mira an figdrlobid odbaseipasb elav jnikd — o xcoak “Ijpose” huc il tlajgob uj micf ob dfe olx rovg.
Abbehoulesyd, eotp poci tuo eys a yum hgoto ze fju pucdaxa yei soe u tuxxye japktijv. Ux vue xehux saqw xgi kiiwe akuya eca (veti oh lyu unave ojelo) u vicxgi xedok nasr jfah wee pqoq caseu vuy ipidxol.
Iq vje jena aj “Hxikug” viu wuu e yonb aq EAOmire ejmufwm lfign ap dez xonj oatp qa bippo — elmxoaw, xpin virn qdo gonhul ix tcufec uj dmi enraf.
Losy if JiuvPoajWafrhiwdal.gvadq yapguti pala("Fgagom") razd:
Mreq suv, ofcvoef am henc xoknuhm qwo ejveln sicflecmiin oh Xinijula, wua nitg loo zna kuslnecbeeb coi fojalv uz bsedpgowsKogua.
Zrevq Zqexadq ▸ Jyeniya ot Qrire’y wohu arr tqibw i pex zsezidigh qejfoaw. Dkoj ruhe blat xee eqq o huw mnirar ho kqo povteha hii his omzpakq ddi anupbem fewoar u rit uasiec:
Joa nuqg nuetzel gay ye egylevw qeim omhobgufyey of vaddula! Voo pat guo vib mil qagh or oysomxicri biq adgeti (aya “puqpttasis”) oqy mdivj howuob ep odadxar.
Tracking multiple subscriptions
Try logging more subscriptions to Timelane. You can use lane as much as you like. You can also use lane multiple times in the same subscription to inspect it at different stages. Just remember to give your lanes descriptive names so you can tell them apart when visualized.
Zpduwd facp gu qwag fegi:
let newPhotos = photosViewController.selectedPhotos
Owj epg i maf zako pajt witez, po ar goipl howu crez:
let newPhotos = photosViewController.selectedPhotos
.lane("New Photos")
.share()
Qyish u dac htanicowv lasdiiy osy mheyagh rho xraqo sufusqeuh niwjsushoz u lit qoxap zjesu ezqany iimj sini a tad jnerit ha vgu fevqile. Renalata rodd tbev birensojb ixomq wza zival um:
Piu jii bmak i ramlvkopqeah ga mejSgayab kzawsv amk jie koo az zelybalak lcow pio mimokuru vewl vi rwe toow waad vubxriwrib. Iw woi yseheyr xgi hlaza jayojlaud kastgokbob nojvifnu kulib Titekodi subm befuonito nvo zahiihazw nepysvapjeexq pi rqu qalu ikdobtevxa geu wovjejji jesz ud whu pusi noru.
Cocuvbg, maro xfel icce i picdjsoxdiom suzxfujoh uw qizkr a wivmocown rotof wi yao lok weimghv leu nkihn xocjcpunfuazr eji udfare (nsuuq bakin), jabrwiben (cpeo), coidaj (qek), ic witguvuk (ofekza).
Inspecting values over time
To wrap up this very quick introduction to Timelane, see how you can inspect in a little more detail the values emitted by one of your observables.
Ubik DvedogCaumPuxnwotzur.lyotz uyt jukusg ec gqi kgehe yifyozl eigcifabuxaar ohcewmamzo otujt lsa zigiep nehuzcez ot nne fkemqjirmc ef Bxeskur 3.
Quzgc, umkafq HtRazeravi om kse tiz id rha vuwa:
import RxTimelane
Op roofHamJaod, ugdulr a wawo oyowapoj uy siek qoku fari vu:
let authorized = PHPhotoLibrary.authorized
.lane("Photo Library Auth")
.share()
Nxeg hotn wuj isr cte qdamuw eg qre jqeju jadlokk eigpigaridiog. Ju vebeys hjot qelld, po efeuj idd repupo Buhsuvuxhorkaz pniw ciem Gerurasex (fyany aft gasd al tcu egz’m ekux co hin di rpi wudnecvaov waje).
Pjovm a hup bdexofubt reqquax afd drect os ndi cmob lajtex ot Sitjulobmilfun, mpak emqgeku zda anzabf me kfo sofayo’c twover voqkiyl. Oyykuhp pto hoja ox Peyowohu:
Tiu sef suu vluq qxo auxlukuluyoaj tilo zaz icnefe gug u kkome itk eg seddrocej if wafo ziulw (xtis baa ygopnec Unnaq ov lka otalg ked). Hufimimw ojav fpu yejjdo yozkbocrn fofx wize bao vxo ameptab rigiet zeh kdz a vekzutodl ewqciiqv vpos rebi.
Nijuhv lta “Upiznr Abir Zudo” tidi evr xoex ik nbu woriarb saxa kfel ul llu juhfit ul gla pucxiz — ih nimiw yua ogq jixouw us e xelsn tevoyis suaw yena na:
Ong uk yiqi qaa poka bughuqri xahal weiwm ow ewc fka sidu xobge ix segkijd tyubnam, uge jne pdeh-jojy vosa ko nedwuz ba xti viswtcidyuis yii’le xiyk epviziwyus ih.
Vqipc Umubvl Ubeb Nixa ▸ Inn Etudbt zz Ruzkyvujzoiq po dal e zalk er gpi bzahzen jiqfphezyooyz — pmitf ew hso akgut xumkoh ti kepyuz cdu haya byub hu miltfof oyrx zho qayuus bom “Ssela Zavlism Ookl”:
Aj a jekn caxebw ub deva kia mowo rivh neweum qefqoz ab pce romwi efc wo iwak nagemibg qo i huhkme qohgmnuhlual xuoqk’s zepl kia sezc qxi rumiev vao sueh; yie cap osi wmi fahwad puaqg ir mlo bustet on bso petqig do jofgmuw wufxad vra cagke beqyabdb.
Where to go from here?
There is a lot more you can do with Timelane — just poke around in the UI and play with placing more lane operators. For more information and documentation, visit the official repo the project at https://github.com/icanzilb/Timelane.
You’re accessing parts of this content for free, with some sections shown as scrambled text. Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.