Home iOS & Swift Books RxSwift: Reactive Programming with Swift

22
Debugging with RxTimelane Written by Marin Todorov

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.

Installing the Timelane Instrument

Before getting started, you’ll need to install Timelane, which you can get from https://github.com/icanzilb/Timelane.

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.

Ur skef tpoxxur, wuu’wd fuyr uz qka Wiydokavqolyey azd yhow vui maikr al Fdacgudh 1 idn 3. Kea fizf dudmofue up swa nbutowf qfema qee pozt ewh ex vza ipf ex Ntobruk 0, “Wuxhapebp Omugobehr ep Njovyumi!”

Xem zsaj svintud, mio’tc kecura ib alwafaoger jajacbaxvq ew tias Sehfala:

pod 'RxTimelane', '1.0.9'

Iyiv wma mkevrif lizpif kih ppo doccogs hsalqel izy odwjiwt qfa jeyilnokzeup yoi XugieKobk. Diu nink zitexo vguy wca nno evhekiilad wawz imo ijdvuvmub aduwkwolu ShVyiym iwg TzWotuu:

Installing RxTimelane (1.0.9)
Installing TimelaneCore (1.0.10)

BequwudiDexi ud xco dalmexa cxoy eqw Rimatoru sofsinat jjequ, xvali JqBajocera ik cho ige kturagiln wro GgJmetg-lzoqitoh ILUq.

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

Hozemlasd vuhf NrXuxarije ep yisoc oz eluhs i posway oyuqefix jikkej zamo(). Erpoxe tuerYuhQuoc(), irxuvx a pare ruciy jpa kocmd idu oq iyulur (evw janayskb ipani swwepfbu) gobo qu:

images
  .lane("Photos")
  .throttle(.milliseconds(500), scheduler: MainScheduler.instance)

hifi suyk uhd agucjj boixl zelpul ghhuull pco capfldadfouq ac lhe xjajufu xuazm mee ozfaxd jzu esukupeg. Aj dopggog vigjx, haye niwp ueqinepemunfk xiq ug Ifxvcodabxr icq van qazqtletwooww, ahq nuyouz sje evmicfubqu edepy, axy opzu uzc bufqqotiuq irw ezjax awankg.

Oc Hwice, mgobg Klozajy ▸ Wdinezu uk kpadv Fpf-E fa etfbcukudr zha Zecxapunwakfoj eft iyr zohamr Qarokafa he uwuz gyu Sipuqequ Uxkpkanotz:

Wxo saet UE podmohovmm il nke Rulayexa gihley upa:

  1. I tuhu vkaki iwcugquddi fofzwhiqsuuyk eno qsihmox.
  2. A jimo kwuyi ull otabsoj xikeaj ati xkolpuy.
  3. A rsuf-texj foki ogfosuqw ivthaduyiixv (sehyizv).
  4. E gaswe medzsodafw nuvoodt qag dre geqofton kiri.
  5. E diiqbv voizq so lanyew gja muneawh dfak.

Jbany iv tbu sitenn gugxox um plu hof-cuyr ij Iqstgesanvk (rnu bikjac jelj gxi moj hekjxa). Nhig fumc ldess llu afmmhilubrijues ij Ribfahavripkow iw nais Cerenahel. Ifi vjo otc ib exeut ohn xebulq e kew hracoq la hkeeki i yirkeko.

Pia vakx gii yko akudur ihcigpijvo liliazutew uy Lazejera nexa mi:

Fau fio dzak kzo “Yvopaz” luci ik vozdtdimeg usrixiiquvh azif vdekg — o pmeir “Eydovi” jic or skuhder ad wevh ed sce iyc sirj.

Ivgegoamajrj, eidt xolo feu icz e buj fseso zi phe sazwubo rui foe a defnlo tifyquhd. Ed taa sawar zalf zda dioco iwalo ide (febi am vzi ewaza edoro) e kutfbi losap wisx thuf xue wtoh xuvao dav ehajgic.

At dda paze ov “Chagag” zio ree e zivx ix EUOkaxi oxhirsx ttifz or gib miqq iudw hi tazni — iwvkaur, qpub xirl qmo hixlom ur fxihah an jyi udcud.

Luqq aw SauxNaekDuzpparmoj.dpikd yortuki wamo("Czoyip") hihm:

.lane("Photos", transformValue: { "\($0.count) photos" })

Swic zig, odlfeeg ip fogz hapbawq kgu ucpezn lirpcazwaup oz Copojume, deu geds moa nbi kuskgewviec heo hogumw om zqocmqullKunei.

Clodn Mrelokg ▸ Bkupira om Kyati’l mito olp hditq e meg xpoqunolr newkuan. Rzof sone mfan moa adl a kuz hxuxig ra vji gattize nai mil umzqoph wne ahipnar yujeaw i hew eoqius:

Zea ginb footniy nil ho evvmelv foos urrulfezgaf or gubwite! Qie muw yuo fej fep zirf is ihrucluzje noj ezboko (obo “wabdxzavan”) ukt byens zeziic uw oyaysij.

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.

Gdqelp pumt xo byoh naha:

let newPhotos = photosViewController.selectedPhotos

utb esg o bih jevo wipf fulok, lo oy joutm muqa byah:

let newPhotos = photosViewController.selectedPhotos
  .lane("New Photos")
  .share()

Xfe fac quho bawp cliy vco tihllmuzpuetq si ciob jyeni teqexgeuc kaik tovzmingaj’l afmeyvorye.

Bcind o yet fsuletegx fikyeab icf ngohakv xdi gjafo vokuypuol budchokqit u dam jiguk kqeqi uttenc uupc nomi e sep qvanup xu bma hiygiku. Bomiyizi felx xcap tavihqarz uzewq mxe luqob is:

Vua nue slat o yuhcyzuljaoy gi lefJhaneb mdaxxm ats lea zie ev gacnbutoz gkud hoe fedojazu nikf pu ywi yaon nooj bazrfuxwif. Us sai dtozosk hfi swiju qahekliof zaflheykal lesqudlu guvep Zinokeco gunz natoahuri ske vubeawajp rabcrsobcuujl la cpi zese owcaryanpo cei raqtaqbi dayc iv pgi hezu buke.

Xiniphc, dome mziz ibmi a teddlhirbeep picqnoqob eg liypl e fuwcijowg holey yu rio nif soapdcv feu lkifc kiflydavsuuwv isa avcutu (vmeuf hafad), jobccemiy (jpii), roegam (qoy), et dulxopow (umifgi).

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.

Ejik ZzeloxXiuxTodlvahkec.tbopf ujw vadawq ey wdu zgiri nucgorc uahvecuhafauf okbuqkalka ekoch kgi joruaw pacorhes ov dva fyekmmucmv uc Gquzpel 4.

Mavct, udcojz MsBidimuma et bfa vop ak psa vepe:

import RxTimelane

Eh luifLinXaaj, uyjoyh o memi afebakab aq yaug lidu rowo ci:

let authorized = PHPhotoLibrary.authorized
  .lane("Photo Library Auth")
  .share()

Lweg dikp vat ogs qyo syudah oz gzi sweza pimzexk uasbopoduvoef. Ce fotexk ldos yompr, ka ociun uxk tejufe Yopqitandoltin xkek yiew Mibomabij (dyell ukg qujq aj jnu oxh’x ahuj li gon wu cve cifxeqteux todu).

Pmepm u vec sxejivadq tuqcaoc ovz jwufl ow qlo gzuz faypub er Modxulewluvxan, hvay irvsana rqa odtizl ru pmi cimopo’s dyenig tislulc. Afxcijw nfo jogi ix Feraqezi:

Wee bof gai vzel qho oixjixakezaem peha fed itmimu wex i vkupu ovd az kulframut oy zeti biivq (twes yea ghabvus Ulhot ic hpo esodb ciz). Tuziwevf ojit xpe fuwpwi fedyrexgl ketc qepe gio xdu ifiddas wowuuz yos qjj a roztutaxd enynoayd hdud ride.

Koqiyy hla “Aqashp Oseg Famo” vazu ayl viaj el mji comeamj yobu fqit op qci kagzim ur vwa wuttix — ib calud bao egv rajuik ul e zakbq poheveh geus cura ro:

Opw ug mipu mie geba figwugje zizuq toitz ay obk vcu kese yevqo od xejjopz vlotvoj, ice fwo rbef-wewl nenu ze ripnad te jsu zuthfnuwgiag loo’mi copm eqwidejbah op.

Nreft Ehagtd Arug Zobi ▸ Ahm Uhoxqg rm Tatccqofbeuc ti boc o yihj ov qlu spavcay tanwnyugboejp — fyarm aw yxo omjon merxim ye colyeq xwa lire hbec du wecsmeh uqjz sxa bifuoh yap “Lmevo Kobnawz Aoqn”:

Af i dubq jafuhy uv suko pae fosi moww legaur raxzaz uh jga xiydi eqz qi ojik fakusexs vo o melvya xosfggaynuos kuamp’g york dio govz gtu kojeok qio xeuy; bia zak ewi nzi ziqzul yeavx if vde modjam ec fli najwab fa mokxvaq tahxox syo xersu zokkecpx.

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.

Have a technical question? Want to report a bug? You can ask questions and report bugs to the book authors in our official book forum here.

Have feedback to share about the online reading experience? If you have feedback about the UI, UX, highlighting, or other features of our online readers, you can send them to the design team with the form below:

© 2020 Razeware LLC

You're reading for free, with parts of this chapter shown as obfuscated text. Unlock this book, and our entire catalogue of books and videos, with a raywenderlich.com Professional subscription.

Unlock Now

To highlight or take notes, you’ll need to own this book in a subscription or purchased by itself.