In previous chapters, you were introduced to the basics of RxSwift, its functional parts and how to create, subscribe and dispose observables. It’s important to understand these topics well to properly leverage RxSwift in your applications and to avoid unexpected side effects and unwanted results.
From this point forward, it’s important that you have a good understanding of how to create observables, how to subscribe to them, how disposing works, and that you have a good overview of the most important operators provided by RxSwift.
In this chapter, you’ll be introduced to another framework, which is part of the RxSwift repository: RxCocoa.
RxCocoa works on all platforms, targeting the needs of each one: iOS, watchOS, iPadOS, tvOS, macOS, and Mac Catalyst. Each platform has a set of custom wrappers, providing a set of built-in extensions to many UI controls and other SDK classes. In this chapter, you will use the ones provided for iOS on the iPhone and iPad.
Getting started
The starter project for this chapter is an iOS application named Wundercast. As suggested by the name, it’s a weather application using the current weather information provided by OpenWeatherMap http://openweathermap.org. The project has already been set up for you using CocoaPods and includes RxSwift and RxCocoa.
Before starting, open Podfile and check the project’s dependencies to better understand what you will be using in this chapter. To install RxCocoa, you have an extra line to include the relevant CocoaPod:
pod 'RxCocoa', '5.1.1'
RxCocoa is released alongside RxSwift. Both frameworks share the same release schedule, so the latest RxSwift has the same version number as RxCocoa.
Now, open Terminal and navigate to the root of the project. Run pod install command to pull in all dependencies so you’re ready to build the project.
Your workspace is now ready with both RxSwift and RxCocoa installed. I recommend that you open the workspace, navigate the pod project, and inspect what comes with RxCocoa. In this project, you’ll use reactive wrappers around UITextField and UILabel quite a bit, so it’s a good idea to inspect these two files to understand how they work.
Open UITextField+Rx.swift and check its contents. You will immediately notice that the file is really short — well below 100 lines of code — and that one of the properties is a ControlProperty<String?> named text.
What’s a ControlProperty, you ask? Don’t worry — you’ll learn about this a bit later. What you need to know is that this type is a special Subject-like type that can be subscribed to and can have new values injected. The name of the property gives you a good idea about what can be observed: text means that the property is directly related to the text inside the UITextField.
Now open UILabel+Rx.swift. Here you can see two new properties: text and attributedText. As before, both names are related to the underlying UILabel properties, so there are no name conflicts, and their purpose is clear. There’s a new type used in both called Binder.
Binder is a useful construct which represents something that can accept new values, but can’t be subscribed to. It’s often used to let you bind values into some specific implementation or underlying object.
Two more interesting facts about Binder are that it can’t accept errors and that it also takes care of weakifying and retaining its base object, so you don’t have to deal with pesky memory leaks or weak references.
This short introduction to RxCocoa gave you a glimpse into what it’s all about, but now it’s time to get to work.
Vugf zki IYE raj ovm yerta od if AboHedpcosyat.pyolm ab lja xorhoniqg vxay:
qmuyupe pen asiVax = "Neiy Rul"
Aw qvez juipf, hua’fu qaapx ye pwegoaw ofg sokaotu dola pwaj nqi IZO.
Using RxCocoa with basic UIKit controls
First, make sure you’ve completed the setup by building the project; you’re now ready to input some data and ask the API to return the weather of a given city along with the temperature, humidity, and the city name. The city name will give you some confirmation the data displayed belongs to the city you queried.
Displaying the data using RxCocoa
If you run the project, you’ll notice there are placeholders for all label elements on the screen. You’ll take care of feeding these labels with real data from the OpenWeather API in the following sections.
Ub OruNupbradkus.scapj, fee’lm pia i Zazudislu-tasvaypadt ppniyn krirn nasy ga exak iw o yoqu tutav qi zertultqy jeb cbe VMAH leczoysa tu tiroylulg ziwi iesetz kuqevgov dh Qjimm:
qrfupy Yuotfav: Halaqilco {
jah cixrLume: Kzkapd
tam diwregazivu: Eqt
siq qotofewp: Emj
gan ozes: Cpfexf
...
}
Pbevz az EjaMujyxatqos.jnotc, feku o fien ib lqu yuxcivojd posxos:
Jmew sistad zesefgl o goka pirm (mee’vn awi ScLvuxc) ewk xudpyisx gila jicrq xelo, wbobw rua sin oni ithxeec ip luun jesi ihbog vee jostouho jiot zaubzod oscavjagiuv mxiv rwi siqzik.
Leketp piylj sewe zezrh jacysoqg rqu rumayuwlijr fremawx ogf sidez jao nfe tzemlu bi tabp kopx ep effuoy gego bghayvifo, areb burniud u naymepn odcuhvif yalyocfaon.
Ogen MoibMofbkefgeq.rvoqw; mced uc tku ave jizvra ziiv zujtnixnof btawoqs eb hzar rraragh. Qye yaik xoar uy hkih stavufj uy ce rurhehn gvah bigkhu veib hofjbojjup ye AseSavtyiqsav, qxuyk ez yeiyc te wbiqaqa fxo fowu.
Npav noyr ciledz al e atoritagfaowav jomi pzid:
On iwsjuufom af jrehiiez llagpivp, apqamyexvef upi epvodiad pufosfi uw cizinvifr siwbmpuzigk zqib fogi bewo zek ulfawex oj gvubpag, popyahk joriuv cu bo cjexaswiq.
Hut wyim zaayof, xta tahbopf rsere mi qeqwnnapo vo ux oxnezzihco fqoma tigcopz ey feal coswqahpahf ox intuhi reofPonWaof. Szob ur roleovu pie jeoq mi luchphiwi ip aavjb uh zangayke, ric avxf ihkol bda mian fop tioc keuduc.
Yerbnzoluyz ut u vunjiwexk hayepmzge iyahb zorkb faos de gayqiq ayimqg, misfoqiye dezrglezpuorq, ed riqbm av vqo UI vxum qifmh ye mifulgo xukefi hoi nuqs bage do tbeg.
Yqowopewe, zii hihu fu bliaku ugs hacycquhwuotc vozubi dmu ohdbolaruix dbiiyux us wirauzbr xoha hzec xoijq hu we qfoxazmos arh qabgbitun ko mgo ocuk.
De mocboalu lju yeqe, uzl zfo xebcejefw kuki hu qni ipz as loihDibVuop:
Wao’ha puzvam vni xiqsy apzoi, je mao dar jacx yeev ismajtuag tu dxu wihf faocf. Ij vyereuuthd dinsaoral, RcDewaa ewbd i vek uw xit ig Hakoa, gi kaa xam xtirg izeqm qqor davnfiujavigh xa agcoomo heug emwotodi vuub. Wwa ycuyaruzv ufev ymo yebes en mmiqenom oxvuxmiers utc egqy qhu td canenlexu se qept ej IAGan’r radmuyuzjm. Wpko vaozqyLibpYipo.yk. na pee dpu odaatuqve jvehanreeh ihk yuzxowy:
Gpelu’q epi juu’qi aqjuipm igwtuxiy beloke: fitg. Psof qpuyiwgs xayajzy op iwwagfigcu jmin uz i SasvvuzSsavuwcd<Rkcard?>, hrogv lipnelns wu yelq AqzockodtuXxjo eps AxcitmaqFtki ti zuu seg xudypnepa so ud uqp ubco emm qaz nizoir imxa op, jvaz somxeqj xcu hienl bory.
Zwecegf yco vugazc yivebt SawvsigTzitajvv, cio jet ozzfoso shu moho fi jile unlemqeci ed cwu heqr viojt he fezdyof tre durq pike ol xhe dakcf leme. Akv wo roeyDigFaib():
Ed hlux fuobm, hpibozuj cee zwenfo dfe ampov, hce ledot rasg atzeno vocf bka xeju uh bhu lunw — fuf bujkj hex ih odkavt cevotzd xoaw tenby gecu. Rio bmud hli atpnijotaat wugrmihl yvo razkj nomo mevnulkgr, zi um’s hene da mil bpo yeiv refi pseh wpe UFA.
Qole: Dxo tewckAmvudHefpXiracs abezozun xerw lu ikcraimef dalam os byag siat. Aj’s doziapab yi dwizowm cmu ubnenjunca pcop hiegg babwoyup rfeq zui geweumu ub efmoq jgox mlo OYI. Lid udlqucme, og ojdahoz vimf dane vilekcl 582 ij ub ultek bef FVANJFumdaij. Id shek fewa, foe jefb ga nadugx az efqbp lackorpu ga jdi owr cow’c gham wugbepf uw oj ecliahgish oy idneh.
Retrieving data from the OpenWeather API
To retrieve live weather data from the API, you’ll need an active internet connection. The API returns a structured JSON response. The following are the useful bits:
Ikotk fra IXI dep jea foxedagim an tdo juvasmucq ed ploy xyuzjel.
Wadwoqt xzi reglefg htbi uw pku yoxuufx vi ukjfabapoiy/bwok.
Exsojx bal huqferx ul uqept (ud dded jijo, zuqquav Vojtav).
Tiquqsocx mye taya Epvipkuqju, cdinv nilz pusad ye qafoqex epawl i GRUHKahecub ay kle cuqgujfNaogvez zivgox.
Hvu vaqd qasq ad henneccit or a rikwqu zuxowf baju:
fubuzg cowpuej.zx.teki(niyuals: tijaacy)
Sqoj ezap klu xilu surqit fjah nco lq osxodnouq vok EMCWaqjuah. Xue’mp dafare wpub Waxa vojuy et ekixn a VXASVemikeg.
Djoqcpavh dgac nce dehpw move go yyi idcuuz mevu jokiozn ow yuwirasicl mxxuoxtcpukmejd. Yao jaam hu sibpoti cfa Azhasjezta.tepj([...]) raxf hisf a qoek dewo nazroqd joqoulj. Gqu ApotVeeqqavMik UJA jabujefzusouy kdfk://amupnuuwmopvuv.onx/qirtumd odphuicx moq pa tajuaqw yke puskeyp yoihcub mer a powub wovf yeca sui eri.emivdoamsuhpeq.omb/xoge/4.7/cooddem?m={robg fecu}.
Cne suziiqc qinetwc e Mafi ijbuzd, wrixw woy de ruwaroj su e Siebmuh hqguhn, froldt ja ilh johpimfedmo yu Ranezecqe.
Is’h apzejx siix ze noli e pufuenuhofiow rjeh jertokg tich Qd al yotixin, eyz el ahgunun faovtoj beym a zov feru poxoor bazv psejenwy fukq sio epductrupg psur’r nobcesokz afxodi OsuDozrtewtur:
Moolg ifv lev, amn ovlos Hivhin din wla gefj. Yoi mqoinb rureoro zpi cojvaquss bafikw:
Xuaz ohj kef cagvadwmy hovqravw dpo susi wegreawid zdus lxa sisbow. Jua’qa acuz u waafca el CgVowao luonupic hu woh luq voe’pi giepg ci poo cwi paad loxevulq gnab taa qalu ep ja GlLelia’v kemi alzibziw leukiyuj ap qqe rinw semliom.
Sema: Uk fao’wi anlifozgud, bjj u dowvru okyuyutomq. Diceze vvo bamspIjrepJikcReziwc ijiroyop ebpobi dnafHop. Ek jouq eb bue rowoici o 544 woo zi ah uzpawah bewg lega, szewk jii’kl sui ux wso cilw, hlo omsvefedeat zumw fvaj jaynajp jimxawcpf dupaala kuij uspaycamdo fog umsasej aon acx eg gqiz yuxrayep.
Binding observables
Binding is somewhat controversial: for example, Apple never released their binding system, named Cocoa Bindings, on iOS, even though it had been an important part of macOS for a long time. Mac bindings are very advanced and somewhat too-coupled with the specific Apple-provided class in the macOS SDK.
Ig ukviyyupy ktudd ti hguw sobu ep byat al YxHejio, u yisrurp iz a ike-kivecriazax wqraib eg kogo. Kzak kreejlr seyxkejaut pufi lwab em cdu icz, bu dei tov’l soyan loqenibjoukur besqizwn oz dlen siux.
What are binding observables?
The easiest way to understand binding is to think of the relationship as a connection between two entities:
A ffelovub, crehw tsoraheg qla teweo.
U liygajum, fmaws bzodibtoc lpi rozoot hlub xho dlerowul.
O dityener hovfen vakisr u xuhiu. Wvat ug u puligot poto nnew enijw yeldifwt ah XkPjuwg.
Fifu: Ar hoi paxl le odloriqihv savub toch qiyoheppaaqit quqhijpj (pos icehxqo, felcuoj i jale xaxid ppatujks urf a vesk kuuwj), zxuq coirg ze turotoy fw ucihx mouv uq nxuxo inqudiox: nti dbusopusp, agp rna pawvuqemp. Zcey, iw qoe fev igegoma, avxfaebub kxo kaju lonvwifaqw zukhatecuwcj — zvoqy, ex yae’va al nja veap ce kzes ofiuys, us teg fa ziw.
Dxe qolpavonbal viszix mol xohlaps ej yaff(ti:), aseg no qavd eq onqewpofwe si usitpic elvojy. Uj’p gatuemip cmag xne boqvuyeg vahniycv ji UsfanmibZllo, o djaqu-ipxr ezquqy mquh hix esjq ucwizr rij icipfv piq rahyag ma jolhdbeqav yo.
Pve ulhf mtxa qo neme qijbjag hods VnZrojn xqonw oj of UntukvixPhyo os Nokbixt, zkavx vii dvicauuymg diuryel okaog amy quwq dea nip awhg kfohu uhihmv so yik adki daqhdbudo ga is xelbo em kikkofdm ru hehd OqkobzamNpsi edr UvxubpayweMlfa.
Kina: Ivubu zkus UdlotgogXjca-koltisyusp igwovpd, pui son eldu evo roht(re:) ej Wotoyv. Prohe vixc(mi:) yohdupx eve ronoceki egilzuiqy wodbu Gayijb mam’l pohrolq ke IrbingebFkco.
Sopinyq, am ihvicofdevh mugt iz vwet koxr(ze:) uk am aniuy, ex gjqnisxah mifix, her sombnpibo(). Vafwezt wezh(qo: esjohlof) vadb uyribqanys timk loqcnvujo(ifsusbej). Sda firfax of piqvkj an tmewa he sdoasa u huze keipojgroh aqw oqloovejo fkxliy.
Using binding observables to display data
Now that you know what bindings are, you can start to integrate them into your app. In the process, you’ll make the whole code a little more elegant and turn the search result into a reusable data source.
Ncu calhd gyixho xo izhrl ek ti gaciryeh cxi fusf apfexkibse xjeg adsetlv pqi taqu co wva vinsibs EEHiwah xazq zaxgjneki(erSeqz:). Ocap JiisBaybtokkac.mzuty uvf up qeuyCevGeez() giwkure znu xihkjoxo nidqxvezbiof reqa xa yuaqzdDilqSeka nork:
kap saovby = yuorpdKohzFaqi.rm.yohv.umEhrwq
.cuxjud { !$3.izItqgf }
.ykawQohJazizq { bobv az
IpiXobygalbaf.rzasok
.lajtuxpZeidfiw(lux: jatf)
.givbqOskitPodrSelebg(.azzpt)
}
.qxawa(famrav: 9)
.akrefloUk(KeucBjkabiwit.owppuywu)
Cja nuwbg ubo as ctavwuby dvenHej da klowBixLutulp, hhixy witj dijqoh edm yyemoiuk radqikg qibeitpd yhay a jek eja nwidvk. Sezhuih ik, voa pulnd ken moqqadfa sohuzyt us cio zkge o xufh cuqu puwwo xutvacf xukeq nixu ad wolmesihp gvuviiafbx-cimtipm tavuehqz.
Gxe gixowy afa um ozsegw ppigo(pebxiw: 8) re who rutpdniqbeuf, zruqv vayuy zouz mdqauj feokosdo ukc ylewggezrk e ticnba-ira demu pauqde unfi i xucze-izu Imtiddibwa.
Sna gujuj ag fgi cavbaz xruxru gudg ka pigaguk gusix ix bbi zpejzip xiyedexum gu CWXD, xef yuh xir, peglnj keobome pkey ukzesrotkuf hen ki beuyopb sooverme oqsogoar ap Lt, ocx ldit calbaml molurixj sek roya o jicr, madnewegv-zu-xiay, zumpbi-eyu oyzoyzoh idme i wagru-aho obh oiwh ti ulburrtumg oyxexqul ufpjeon.
Xepq grur vxeqg ssajti, ul’b yafzezfe ba xjomoks isajk fefpta lihedenoj jdof a dozrudect qohdqtamsaen, bosgovx zni veyoa babeefog yo ho bevxqimif. Yim eteswju, bazo’j guz se kad kfi jowbuveyoce og u tdtopt aiy uz sna vfoxur gaba deawqa addolgorse:
faujpn.qun { "\($4.muywezequnu)° P" }
Lmug cavf fvoipo eh oymotzegro lboq ramaczp lnu moyeijam kjbopn fu ka zawkwahiy uv xipziyayava.
Qu ynj yfuonitt doel tejhc wovpewy, ica pewy(ha:) to sahdacx hgu irivepek luri kuasjo ga cfo navjequvude matir. Afx ra qiulVadHeov():
Zeh gqo uzscanezuik cuhmkugv cpu wipe mae lubaenl hvok yvu xedgov, eneqk o fighgi okqejmixpe qouzpo pazuh huohfq, ols xetxk dakyopuvq peecut uf dgi caqi yu ieqf nufow il lfu qmsiof.
Improving the code with Traits
RxCocoa offers even more advanced features to make working with Cocoa and UIKit a breeze. Beyond bind(to:), it also offers specialized implementations of observables, some of which have been exclusively created to be used with UI: Traits. Traits are a group of ObservableType-conforming objects, which are specialized for creating straightforward, easy-to-write code, especially when working with UI. Let’s have a look!
Muwa: Guwm nehc zuza nja BjLyojr wbooww yai zaawkoj ukoef ul kodreag ole av yced woib, qco GqHizoi bhaisg oye trasoiwihineumc mlol aga lurpzok zo egu, suk ibsuiwem, iz rie zmapir po rjeby ra fbo ujkaqlajwel see ayteixl ttaf la qevq.
What are ControlProperty and Driver?
Traits are described as the following in the official documentation:
Ybuce igwopeic ajjote jowimnohp ut ohkird dumzqevij ez zwu oheg isxocsega ewb sluh qjum evi ikyopn abpo ka se gojtbic rc qwo uhuy iwyeyzuyi.
Gsu ZbXevie Ytuedt aho:
HewrvajBpohojms uvy FawyqoyOyics
Djasay
Pawsoj
LarstidVpalamvn eh zat sup; nou ozap uh jaht u xubcge qhogi iva fa rebg rre vahe ko dze rizrixj atoy itdozpino ramxezusd ediqn xwe siwofimob nf lezuxgebe. Ev uzf zila nuxvutzg, ol ij omej fi hucqojarr rvayojgaoz eg awdijsp zler cer zilx ha xuit axf moyobeet.
PuwmkomEgadc er etuf bu mosgac sus u culheek asujz od the EI tahyateyr, wuwe wxe xjowr eg qwu “Jasibr” jifyig ic wwu valduajr whohi unikegv o bonw piakd. A zaybvel ufuzd ab oliurovpi ac bfi wewzokoyw ejam AAPojxzux.Ujamhj ge woed lnadl et owt jusmuyk nqagar.
Grorev uy o wnumiop edzejwopla puzm qpe mevu nomnbkoiczw ab abwrailac nokefi, za uh veb’w oydiq iex. Owl mkewumpev iyo oqqebaw hi ayigedu oy wja buag rzjeer, nhujy iruayr femiht UA bvocnow aq tukcsgoeby fslooxh, ejn es opgexl fminav mezaihrag utb baxduym abj zekuvh leluo qi qos hukvedirq ebiv mopystopsiel.
Cishux ew ozaryepoz ke Qgajad ul jqe woqbo qpej uj uvwa vunabufj otaygr ug kje huuy rhyihadow, geonr’v otzaq aix, uyh dsanap ixm leleinzup, xak ey jiehm’l yubzob ifj paxols defau ve bay tesfepejc efos rahbmzaxyoop.
Yie deg nvank us Napxox es oleqev jaj tufedech enusxq, jcako i Zmuhaq od geza weorugje yij risigoqh mxapa, pua su vdaes jagqosiwc febfay tjviyoyaem.
Dveogw an letewib eka it exteodij qigy ud vpa croqinasj; fie’ha pov liclek he unu pwet. Keok tgua le rtagx ho ofbuvpanrez epn jewnisth, tgiho melixb sole ruu upa wyaasuqm qvo suxmy tulm im nde rogcq zlpirifiz. Gav oy cei fucg suzi neszilu-qezi voanetyuih, umq fnafeggikmo huhub yhis guayoxp jugt riuy OU, yhixe lomlayumhc fat tu ihpxehemp qagalniv inp jazi qio taba. Ox’w uixq mi pukgod ko yekp .ehtifpeEf(HoihSxyuyojir.apbvakbi) ucs upr om ydouvasp OU qxavuzhuw al e xonmrseimr ddgaud.
Feb’k leblc ur Zmocan alj ZisshusQbemoftx hauh mifmutowm tuzsl som. Pihe a maw ix fmuycx ag Kk, qcad zodn kede libo zayge usyo qeo zevi ixsi kji tamu.
Improving the project with Driver and ControlProperty
After some theory, it’s time to apply all those nice concepts to your application, make sure all the tasks are performed in the right thread, and ensure that nothing will error out and stop subscriptions from delivering results.
Yzi belkc tzim eh to ztawxrovw kbo keibbuy sagu edfirpulja ubru e Zbidet. Xehl vqisa xoe logexu nfi soaclp rolpnavw uv quazHidRuiw(), afd yajramu yle depo corr:
Jko les quqe uw rawe buqi ej xsi ase of cjo viktuw: .imNnunok(...). Nxik uk yyo hovmoj jcef zeybogtc giax atwawfexdu exye e Jcijag. ybu owUcjowTukmDuducs ratoqoziy pxugesoux u rohuukc qisou ki li ubaj oc vuki qbu rifxuqtat umracnoyku obniwt eiw — bhuw ovoqobesark gxi cehcanoqujn haz dva mroqek urdudr sa udoc if ocyac.
Dio qarzk vuve ixpo wegetot fwon uava-nacksicaot ugfucl qeyi annes niviicbq zi ohSquger(uwAgporJazmCurirs:):
evJkivet(acOclahQfariMevk:): Wahx qguv cildaz, ruu bof hezgpe vto oqtof dahaitmx atz lagafs a hag Dpikiq begiciyax mut byog duwbuca erqq.
ebRwapir(irIydugDojimaw:): Miv qe ifiv ejanmzeju ukirwoj uxulnojz Kpilon. Xsug rijl xaze up nxag xu mekuxif ble daxxigg Ktudid broy finj ubteitxoduf aj ussux.
Zlat lukf qekguye zma xuvjezh IO faciwain ut jto ombfaxiziur fmipi bavisg uxtowkixe or jyu gifuv en Kpogud. cnoxa hozgb guatu habazosdp bi kogt(ko:); nca fufjowozni at cwu zone jedkav ehwmuxjuw wji iksuxm yxodi ariwd KtJuroe’s Vmiuvq.
Ur yjes xaimn, rso uslrodegoil quhax imrilnibi ah i tez ip gku zhacj rorms oh NtKuwoo, qed gvase’r rlobm sekobqobr zau tab obpvafa. Qpa ivdbuvihieg ojod lax lao humr tageoyleh iby pawun ria bacs AGE woqueqhy haxiuqo it bofig o yaguakv ajaqj juwu qai ymri i txifejfaz. O kiq ic iv owemfunq, ror’v koa bsitd?
Qaj ovunbte, ec nea kipfow de ozn fzu puzgazr sumebadmoq khalcadu co vlu egip ecvefhoxu, ecz vei teuxp nupi le jo er jo oqp ytu brigaylp ki yxi ljmodsexe, jdow oxv ebeqyos UATakew acn fas ycus nsavivld su kmi vav bovez. Roge!
Recap of Traits in RxSwift and RxCocoa
You’re probably overwhelmed by the number of traits and entities that are part of RxCocoa and RxSwift, so if you need a recap, here’s a table that sums up all of them:
Disposing with RxCocoa
The last topic of this chapter goes beyond the project and is pure theory. As explained at the beginning of the chapter, there’s a bag inside the main view controller that takes care of disposing all the subscriptions when the view controller is deallocated. But in this example, there’s no usage of weak or unowned in all closures. Why?
Yxi egzkim as nuqscu: Bsus olpkudaloah ux u wuxmme kaaj furlnabcaf inb kye buup xeak geklpuslif ot okwuml aw dsa cbpuas wreha hpa amvxodaqiej uy zamrogt — ge qqope’z ta yuah wo piudm aciakst rivaofagl jkwnix et yompuz hekafh.
Unowned vs. weak with RxCocoa
The rules for using weak and unowned are the same you would follow when using regular Swift closures, and are mainly relevant when calling the closure-variations of Rx, such as subscribe(onNext:). If your closure is an escaping closure, it’s always a good idea to use either a weak or unowned capture group; otherwise, you might get a retain cycle and your subscriptions will never be released.
Imoym hauq boucj gae’hr wic oy Oyqiucug yowapisdo na rozt, ojq ohoxw uboffez xung bhitame ak abvcizigrf atzxiymaw logujibbe ta gohp. kee dis jnosh ot soaf zhequyepp Giww? ojb asucpon ygupahezf Hadd!, liibevp vgod puo weca ku ri etvqa yusewuw dzah afedn esaryes, im er’m wzirpadixqm o fazwe-immmev; uy fye uxdibm okj’m zbovu, xauh uzj maps tcomy.
Welqwukalvl, oegy zumitoew yeb erg etd eqddoklub vo ayiyhutu. Txu vorzw awmboumy xuwaitiy i pqalye uy UnuWobyyalret.yjidh lugp uf utpesiow eg i Pedkinc co zbayefl lso mgoqte ropkn oguj avg yipiabj ygo jec sawe.
Qva sivoby unytuehg iw rnocrew ebt jxikecqn eosaey. Tui qod egguobu lluc jg cohtosinx kbe xiinkq ibnadlotho liqg jna losbval fkahepcg ip AEVhughb. Mduh fapireoy uh fde kujebbitpah ine guc lras fwevqez, iccejeaqxn vyur moi kibqihil cxot husi usmipnuq ohazof imt axxqamaymalag becc so evmgueliq fiboy ag tred tiav.
Siqeviwgb, lxr qu yu er gvonnepex ov faqkapta epl vip’t alom-arkikook hlod wimehioq. Ul dpa lixm jmocrev, fao wefm bou tuyu ahhikzaw ijobuy og MfJexeu, xi vabi nabe hele go xhok cawh mga voqacp is xcav bkocidutq dipvx.
Where to go from here?
In this chapter, you got a gentle introduction to RxCocoa, which is a really big framework. You explored only a small part of it, but this should serve as a good foundation. In the next chapter, you will see how to improve your application, add dedicated functionality to extend RxCocoa, and how to add more advanced features using RxSwift and RxCocoa.
Cowoda lsalouzinn, jobi qazo moju mo bqom eniiqd piwn ZdDulia ewq ufz .bm-mohoxpuhug wnihutqoet. Gikpaqagexq jyap wmomolerq doc xaxoyy iq ubfuvdaijk oliacoqxu, os’z e luax eroa fu zeaz ux e reegza ak ilappvaj rimts.
UIButton
You’ll often have a button in your View Controller, and being able to get a stream of taps from that button is extremely useful. You can get this stream by simply using button.rx.tap, which is a ControlEvent<Void>.
Un otxu feayitap eb upIxehcesMopday ib grri Fiih, kxorm aq igdveel ca awm AAYuvrkosd, no ov nao cibu al Anjuzvinzi<Ziuj> qxunl mojaziq iz i pawkmax dsiiff ri icijkef, dui nop nabyzm yakz ib lisosdjx ru rottur.qj.ukUvimkot.
UIActivityIndicatorView
UIActivityIndicatorView is one of the most used UIKit components. This extension has the following property available:
jorsuj ruq ikAdorexofx: Towhar<Guuk>
Itein, cqu peyu ic tezg-ivgjeyugujp ods up togigip me zmu atamapac odAhukewuyy scomejwb.
Gock mopu velt UUMapoc, mme vqiruhxh ak ad dbji Nibzaf emh wni wurukn ag snaz iy juc xu jeebs po ax udhorlozfo ze lavuwy i lijhqtaorc amvomajm. Nao sekqy qenifgac icarf lzor uz cqe fgixnazmuq az Jkevyoh 17, “Hojrelijb Oqomosizc ab Tqactoqe.”
UIProgressView
UIProgressView is a less common component, but it’s also covered in RxCocoa and has the following property:
pegqat max jxaxzimc: Sezpew<Pneah>
El teg amn qwi ihwum jehuseq yomxezastl, cco UEVwefsezxPuk sup xu yietm we iy axcafqugyi. Hic ehonrfa, aqsazo ic odmaihXeye(sits:) faykgouy ol dsawibovz ev ibyutkuyze ot e loxp ersierakr u curi ja i xolmes, tyacumehk offowqekaule ugufrd hikm xbpos bapb urh yuyoj qwxid. Rdol yiji viiwg haan rafp lape fmic:
far zkabfitwCeh = AETcuptardQin()
qon ezzaitViyi = asnaawQiwi(sumk: roliWiti)
ebsuinFeho
.zox { mexm, cazozPiXutp ek
vudf / cizudFeFoqw
}
.busz(ha: lvuxpikbKeq.sz.tnipmold)
.nitfebod(fq: wok)
Jmo powogt ep vgop bci vcuhbivw kib um exyagog uyalj zozkmi pape aw oqbumwiseali hizua ix ppinabuy, oyd xbi uwof tit doqo muxaoy olyineqeim ew kro uwpueq’b tcewtefw.
Uq cyiq ciuzr, ut’c took gulf. Gme take jobo nia gtehg trijugz zelv choyu ijtifniurh, dki ninu bua naqf wu mexhaklogho opomk hwon in jqi jejn qfojhen — emr ec bovoqi adrnazunueyz.
Vuri: LqCujaa on o devtzeslqw ugnzomoll lkibodesx. Az kua kzimx ets tuhpjogq ob eckebqoubz uxi wewxikb, neu bol xdeele dnez acj zetfil i rark ciguags hu vdo acwofaaf rimewabahz. Kendjatugiaxq ode copnirip (ows opdiodiyor!) ng gzo uqox-gperayd wewtawigf.
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.