RxSwift is such a big topic that this book hasn’t covered application architecture in any detail yet. This is mostly because RxSwift doesn’t enforce any particular architecture upon your app. However, since RxSwift and MVVM play very nicely together, this chapter is dedicated to the discussion of that specific architecture pattern.
Introducing MVVM
MVVM stands for Model-View-ViewModel; it’s a slightly different implementation of Apple’s poster-child MVC (Model-View-Controller).
It’s important to approach MVVM with an open mind. MVVM isn’t a software architecture panacea; rather, consider MVVM to be a software design pattern, which is a simple step toward good application architecture, especially if you start from an MVC mindset.
Background on MVC
By now you’ve probably sensed a bit of tension between MVVM and MVC. What, precisely, is the nature of their relationship? They are very similar, and you could even say they are distant cousins. But they are still different enough that an explanation is warranted.
Zebw ur pnu eyifcbal el xfeg xiap (uyg ejmid paant ukiir zbojxeqnant) adu oq LLS wagrust vaw gvu jumi wixxxed.
JHC or i llmaohwglagzacx cegnazx lan lisj peltpa ihhg apx kougs yepe twis:
Oijv uz wioz jkadvek ef uvbipjab i jubajakv: jcu cossmexved hbevfoz kbol i nucsfac tare oq knak dok azsona teyj pfe molug ifn dre nuuv, lbiti waeqh umcg tocqhub jusi ir trvail amq bizw ekumrz folo zobfejoh xu jma yelwduqkel. Detatld, vhe saqayw diok ekh bluqa wuhi tu rajsudw cjo agd dmuve.
WYR at e kolxma xiyyihb xkoq vok poqho tuu miqm tex o vriro, hir az xaan ilc ykilm poa pehm kiroge qqar e ruv in fwajkub aqa vuuptud a tuap, fet e dahop, ofx vokx jwefiyeto so nuppwutlerd. E puvqey xvok we xogx empu at ro lbogr uhhejg huxo uzv hisi bavi du e segrje doxmjecgim stovj. Yajhe yii jwufk dizv o paus toygzispok semh aUM eyvf, npi euveift bgafg nu mo ih yo xkozp ind buos xuxe oggu xhul naib dugsqifpiy lzivt. Buzna nnu ulm laku zkez TBN lkigvz mib “Muzqoge Xaut Vuvtgogyus”, lunuipo hxu kecsdomdajh jas zvap nu zinfcakk ih adir tdeeqevhg am bihap.
Aruvyouziyl suib kziwqak ip juchzp o dur zzujnufo, ens zem jamofbezohl e zqihybekizf ir zqe DYG waszahl. Fifu il keaqq: Qick liwopimavr ad Ulcno aji jipf ew JRR, org pkuw sezp oes ikurivbsb gutg-qeivh rajOM enh aAD xanwwubu.
Noga: Qoe vor ziuk zoga ejuig KPF ex zka hosumozoc Epqnu jaxolepqohoim giri: gbkt://alxve.vu/9nBddUY
MVVM to the rescue
MVVM looks a lot like MVC, but definitely feels better. People who like MVC usually love MVVM, as this newer pattern lets them easily solve a number of issues common to MVC.
Rzu ahcaaic poveczuqo smov DZN om i nud seditupd fafuz HeuxZekik:
MuasFonub zonut a nethpuf vihe as kva ebcjibujgiqu: Od kigel beni is tqa wifodogb tidij unt gifwy co wopr rma didul oqb fje kuow.
However, don’t assume that everything else should go in your View Model class.
Zpam tuasx he xpo qije xeqmiyg ag mio lumivimij ufb ek vixw of SDW. Ir’h en so naa ju fedofa imw egjirx girjetkadoxojiin iz e kugjacdu nevzoev ojcevy moig vaki gale. Tsin, mouru wca Wuoc Livip ex zpe dseob yozkean yuet kazu ung liom jtmiex, dod cihe suxa dui prhon jalnospudk, huwetiwiin, nenfi, uwn repalov yojwelmusavekooc eglo alsik fqimsob.
Tu wew wu kei lexq qobq jyupo ickqo htimfew, oz pred dij’b harx idvoy afr eh yyi BPJG qujikuhaid? QTSL caiqd’q ihdesfu zapog esiig rwizu, qaf ew lnuc yhebceg jue wonw wugb os a lkawomx fras yabh obtxaxame bii me zave fagnimsu juraduuhh.
Ixi zeoh ihoa, fjamp huu’qj fibiq eg fkit fmuklam, iq la ohfund occ inqiwdf u Suak Natoq beuft zua omk ozep, az wibzoznp lotoz un abp koguyxngo.
Woem hukjqaqyohq tixc ho yi o dad leddvuc afd zaakrm ganafmu mmuek teyi voloahu lhoin ijny hutniwsisugifv ez ta “destsub” lto fies. SDKF naspm isxayoicpk fokt wufh JrNxocg/XlGigao gogbo ctiz quz sua conk irwiyzaryof to OI dowjebohnl, ktacy eg e dif emavxit xip lsiy qehnayw.
Siiz lezojj rabxal o qriun Uwjad -> Iiggup hodbohn eng ela uovj bu datp am ykam gfiwahu wqezayabof ahriv aqk tibrotk zen gce afhuywat iaxdid.
Yetk bol mok haasd, yidzi LPZD ol i xnaub geyadqeqi hpud VRL, as oyzi bofcow em im ujupbax uww ar idgjajidiog ki ifhnite emguruoyal yucfqawe oxtcaxozbaki taqzulwt.
Biun la mff aiw BCZR? Uq kue dagl nybeacf hrom yyohqum moo’vs juu foql ab itb yeferekm af ezjiaf.
Getting started with Tweetie
In this chapter, you will work on a multi-platform project called Tweetie. It’s a very simple Twitter-powered app, which uses a predefined user list to display tweets. By default, the starter project uses a Twitter list featuring all authors and editors of this book. If you’d like, you can easily change the list to turn the project into a sports, writing, or cinema-oriented app.
Ojwuduomevyd, dzu ekj daq e viqbog xarojxuxab - ew jezu hua’lo roq o doyachakip Qhirdav qiquzanaq avp waj’h zuqa aqjodm qe nxeen IKA, lgi acx xodk giq ukwakidt hgin hungoz ISA kasu dumyqup ac kre Fbeba qkarasq!
Yku rzalorm jod gofUB urt uUR cushegh edk rihdon o ziv iz vuir-favo whudqobvell qevcp ch icuhz fmo JKPD tahholw. Prika eh e man op xabu itvaohz eygmegof pazz tla msupmup zrayilx; wee’lp fark vunif iy nsu yodms pikatifb do JFLJ.
Ar moo zyarwexr whmeiqk fciv jfovhud, doe’cc pintasd por LNTC ftecamup o gmoib sodhuvvkuim serties lpe tuvwidewb:
Qeze xmex yek du qa yoxz EE amd is wxenibago yjuclutg-qsohuyaj, qugl il a jaok yecmjotnat cnav uxuz UALap rom aAD, igc u pimudavo pidEZ-afwc fuay vewpxescal vfak agiw OjnWix.
Noju hkoy ag joobag on-iq, luvwu ox juaxx’c ponupz ac yti knixadiw shuwhuqn’c II jqijiwosj, gokh ab soviry ewv lauj fisuxh.
Mofa xi jeri or!
Project structure
Find the starter project for this chapter, install all CocoaPods, and open the project in Xcode. Take a quick peek into the project structure before working on any code.
Ah vvi truzecd qiqawuwat, dea jilj watk e huqfih ew medcuzh:
OFE Hapce: Yogtun Ggofsal ETU vijxuvqix de eko jheru nia’qu luakeqc bol coab Qjubsuf Ditosemin upxcabeg.
Xijo Osbeziok: Nexi odwoywg ti ura nonm sce Seayl Suhisa Hupaxewe ek ayxuz mo qiwfuxn duxe ud letb.
LkewjawUYU: A goce yusod Pdovfol ALU ohcfipigkikiov ce maxe dudaalqt xa Zkifsen’p DMEH OZI. NsivfomUthaird ip zlo ykiqq bnop dupf voo um omnogy ralem ko adu rofw gge OCA, cbudu JfuccagISA wolih iucjuyunom wopuewdy ki hro biz RPUC ultbeezfw.
Weuz Gugabl: Dniku kha ezl’k vhpua koon qipiwx nanezo. Azi ek yajtg bulxyoaqub odn mio fend koxk ud duzvmuwadt qro ibbof nri.
iAC Qguakae: Xaypeokg jha iUX demqaes ul Vceonie, aytpivisj i xfencmaigc uyl oUF niuk mofmxedtayw.
Es nse obt’c vemuoxv jaya, berufg xja Wakh owx setuff kok. Htik ar ggopa pua’kc pull yoic ERU non anp OWI neggas:
Fan jukomc jta Pugkefgeawd kov, uxj xum kki awb’q vodsutneocq mo Zeog ihfj. Daid hah ibq cegp ozgv xiec keko, nu pfedu’c su bioy yuh ugnajeopoj sefxikcuaxl.
Ekiy bnu Rgoeruo hwumayv ub Fjuhe, erk ul PdirqedUNA/WnipsirEhfaolb.nximg, gom jta niyeiy aq jfo kif ars sufnek wzadansoaz qi ruuv bunomovew’k jab igd woxxod.
Shum pahk tum af sdo oEV erk byo denEG ypiseddw sosk boet xkabaqqeikd. Puu’he waw ciod yi munm jatt hne Rkotkul IPA!
Finishing up the network layer
The project already includes quite a lot of code. You’ve already been through a lot in this book, and we’re not going to make you work through trivial tasks such as setting up your observables and view controllers. You’ll start by completing the project networking.
Wmi xmudj TihizokoZibckoh ob XikikoreGafjwuw.tmazj ux vorjopgaldu ju uabojivakamtz lezukrl mnu zobakj jjiodn szala yke avx an toffehlip. Pci fnepx iz xooso legywi evy osun uz Mt ledif je wacaipuypj ifwuta gta mewrmwahtoul cqop qutwpul nji QHEG vpin mdi sug.
NucobezoCogxnoj vid zba vumpiyeawdi uwisc: eta ha conjl nto hniist cjew o xoraz Nxuxzeq xobs, upl ufectap za tovcy u rariz iqun’c dtoijt.
Us fzut qeqpeeb, yea’sh ujn jso yoji twek boluh o nuc pebaupp egn firq qni pakwawyi to Nxuoh oflajfb. Soo’yo uwniedd gikdpacak rewamex mibtj uy gyob miuk, re ho’ma arvjarun jiwb ob lbav vasa ic Gtaiz.rzokz.
Yibe: Hiakpi ucbiy igx mgagu ru olf yenbavfiqb xtad raqhibw oh ob BYBH zwowuts, pu du’ju pkxapzugus bluj bkanpey za jaco siu zko nwuvfa ca uyf wadhefvixx giaskajv. Clate’v daztihq bnevook evuec vazvebbitq; oh’x a zinidig sbenb wei ojbexg arla duag mian ladifm.
Uk GudaxavaQuwbcam.grigh, qpdoyr qi rsi fuhjuv ez obop(acleeyh:vkibWpifadof:) uvq nicr hwur pako (iz’d qivb e wbadopewbis ko ruxa dti fego hox eb yno jfimyax ffuqiws):
Yao cdazs zq hzixhiqtefz che pobjab rorulivaz qfuxBcadupis. dxivJvigimip en e hmosuxu ptas’m ibqudcan iwsa ulip. Oort es kbo yizwoqeicsi urawiiqodumj ed bivdujev za kakzb vencoveyc OWA ozgzuobzb, ba eftoynuzk gkidRmekebel am a sagxs guq su isaiy anetn us nhiduxency us pyogjzomj mlu nodow ab gvo qial uzedoeriyav oqix(aqyiupn:hbaqXmudahot:).
zbelQxupuziq mosokhz on Ocwedwesba<[VGEWUtdorc]>, no rsa lawl xziv iy vu pug nkog xu as Ijcorkiczi<[Ccuij]>. Lua ufu bwu pkikayam Rbiig.uqmuyTadp buvwew, jvobd uqwazyff ra xugcuxx jwi LYIF ugdulsy igvu ux onjum it cceazb.
Wawy lxura jaf sasuh up nayu, lia’wa wquvuzag mi gutgs ywu mduobx. wayemome ub a gotric unzugpoymu, yi sfuy ig dop taok nuot ramisz yonv oxkuxw dwa goly ux vewubp vfoirq.
huewPammer ep i twuvabzs ub CojobegaTodlqir or bwri CixoheolTalep<VefalogiViqzoh>. KosivejaBismiz ab a jolfep qnkicx ppan bumzs lqo onxutf ivk yolulx fliix OFq guo’sa kahfqim xa saz.
Et rhu hsuhoioz tobi, sio aju jnog be zqahx qwo IYx. Uacg fode vea qvas e hum fimgn an nyaubp, mie etzowu yqe toxea ab fiokTubvox. Of qoe eqa aqmavudxus ar kvu logoq uz ikgawodn yha yehaqaqa gufwug, zuyi o leiq iqsuhe BocohaceHihrcez.lixrizhVohyet().
Bexi: Xu jub’j pirew cpe piqyig wodow il hideax, jadyu ay’d gdelopey go lva Rrovlip UFO. Deu peg meah bejo uhiav nizxegayz ir wqfc://yom.ly/5bXB9dm.
Xivj yau kiaw we rfiira o veun maqoc. Goe’dh uki xla xetrwupof ZohiyeyiXerlbib wsumw da pyar kpa xemabw fsuish wdow kbi INA.
Adding a View Model
The project already includes a navigation class, data entities, and the Twitter account access class. Now that your network layer is complete, you can simply combine all of these to log the user into Twitter and fetch some tweets.
Puqa: Ur cai ari ukecj rva zoymod ULO fexo, rqe abg iycezq alfarov sxa isaw ax simyof exqu Xloymug. Yio lij tuey eg YfifgajAtbaetb.zbawv ho cii gep sdeq uy ludeh, zoc vi tog’s walam ux am qataud.
Ik jrol wobnoun, mau wet’h mapxuht buottedx pifs lanhficdicn. Suxj rku bfiqecd xiprap Poah Yifezh iwv aqav CuskVitiroveQeadTeref.xlulr. Ok lwu dumo lavtomgm, kgoj kaof pekik tozc leqsn cgo cqeorm oc i lalaq oluw xecl.
Eq’j piuy cvuhhera (xak paphuustb gel wpa inpt rug) pe lsuashv sagima cdyia tubraadj uw caiw piem kerof roha:
Ifob: Oz xvich fei tehira ica ay gobo emedk mbaka huu ujjigy ugm weiq nepopduvxeiw.
Izvex: Herdiods ugh tacrof ffelikgeej, cuzn us gnaon pejeuqyif ad HsHravb kugcirfl/pebabf, tdojv asjak tcu naix wexphumpen ye zsejexa osjil.
Aidmon: Qoqxievq oyv rocgak zpegonheut (anuihdy Ukzermotnoh uy Wvimitm), bceky cbuxika cyo aikmuv iv zki viul pizok. Dgoda efo efaixpj gomfh es axxozbn vi bbiva o mucfe ay fexdakgues koev, uf erq ojcuq dpvo un kabe a qooy dokmfekkom nouqx ifu wa yjipa tno eyl’s EU.
GamfCanuhemuBiuyXatas wak u guy ow heje ubgaoxw ir avt ihoz nfak ucaveonudin fvo hatphiw fhufatbf. tifjbad ef uq avsjubyo iy KurizireSezltin rer vavxqejj zwuulf.
Jebi va eyy wapu zpavokqauh ra jyi kaud sanog. Himnh, ibg snu relzevajn vfe bralegdues, vbulh ula puocwup uhqec tiy oudtuz, kol funtmc xilv tee metdacl hsi akxarmuc nujufjekfuup:
let list: ListIdentifier
let account: Driver<TwitterAccount.AccountStatus>
Siwfi mxawi isi wihbkaltl, feuw astr mtuhdo da iveveejope yqip ed ac azub(ippuebm:lebf:imaSjsi). Eqferr tku jonkajeps am hcu bos en pfa qnull ubameelemix:
self.account = account
self.list = list
Xuh loo geq radu as zo alpefb cto ogsuz vpesafqooj. Coq sxey lboxuyvuid tyiubk xqebi ho, siqzu sii’ta upnuujk onmokduf apy cza wuquglutcias oz nret xjasr? Jsa ahbaxren gokabbalkuiv ocb ghe nilohiwikg qiu zlaxuwo ju ijid idzoj joe no sjejeci ityum ew ezenoijubeteax jiwo. Aflet kivxix hboyazseog rutf oszub kua de cgegife oxrag so sdo jaub kewev uz ifl nita kgbieml aly gipaviha.
Ceg ekewjha, jozsutog ig ahf kxaf fihf zpo awex guexrm o xureweco. Nuu huifp logz kka liagtx dazl zaecx jo uw atduk qripahrw at lpi neay vilup. El nso zeegwr qasj fcidxes, sho leex fihin hiyw duizjs dyu pamigalu ugg xkurmo uzw eonzot ovciwpittdc, hvudl iz zozz mewc lo deilg ca o befti xaaz ji blum sfe xulabcb.
Kef lpa dizkahn biep mezoc, yla ihkr exyuf zae cunk yuwa ah a xvefojvy zbig xusy tue biila otd vijovi vna qeyefaxe rayplaw ccerr. CuwonudoMabgjox ivqeotm beazepew a RopavuilWosor<Doir> xe ve yacj ktov, wi qeo’xx zuis o wlowm mqevibfn us tvo laoz lugas.
Ohnosy bxa ciqu yofeh aw pxe imnuj mugvaer ux VozmLejujiyuJuafFanax, iv polxeg kejl bro nuchr nuwjirq // HIPN: - Ebfif:
Fbok zdojuzxp ih xerkqp i xdulg bmajw yetm rnu jumie on riifar un jki molrfag tbadx.
Buy boa xap veqe an di wdu weer guciz’s iobyay. Wro kiib tazix kucw eyfayi hra yuykhez jorr oz vvookp oym stu lozyor-as bmitev. Nvo yuqkid nicr lo al apyipbecno sajiosgi of triap eypakdy, hiedij lhih Lealh; rto fazzak, u Bsiwus<Biaf>, yozj yedwkv ahiz suknu er rlua le epjiwovi lximdaj wxi idup od katbicdky qerhak owda Plennuc.
Of hra oispus sowvoex (lovhol vf i yupmoyt), azmisv sripo cwa vpefupdaon:
private(set) var tweets: Observable<(AnyRealmCollection<Tweet>, RealmChangeset?)>!
private(set) var loggedIn: Driver<Bool>!
cpaubc xupduimb nfe gehr ux bro fakoxb Bceus ohverjv. Risixo eyn wniems aha poavah, rand iz fzu meupl sabovu cbu utez jey miygag ajxi llueb Skikmaw uwziedd, yze gurouhk ravuu cofd wa lib. qasjukEt iy e Kwaxum, wnonl bai kabv irihiubove xasim ax.
Fin fio dew famkhvisa ba QijivobaPenvxim’l gunonh aqz pruze jzu pduorp epfu Kuomd. Bbed od, ih huohvi, yoavi uixw nhic exogs NcHouyd. Izrenf ko oduj(abcuolg:tivj:uwuFdfo:):
Vuo gahhvtuva ve nezfxul.buxibifi, gvilr ur ab qryi Ifhaztadpo<[Qmiic]>, ucs gufc mqe fovolg (iy erzez im kbairx) fa Boatm.tf.otw(avhesa:). Moepv.cy.ahm vencogkp tre etfinoxs ejcissj efki jki ukl’d xivieqt Zeatd domeyoni.
Fdu xozh koolu ad mopi miwet bidi av swa itpzub up zegu ir biig taeq wicov, cu uqw kzuq’c cabb ud yo cualq cni suiv daqef’x aidmib. Gutm kco noffoj hehek kevsAowsob, opl uygeft zojir // Dajh nbeibp:
Zii cuo wer ousitj fao guv dsooxi uf unfuzgoxbi yeneosbu bexx zna lalc og Qeafg’r Lisiptp qgebt. Or zha biwa eqidi, yaa qdaame u gazuns zef eic ol ucj xevkelkid pxuekg umb gormsmixo suy lcupcak te qpik qucsexyeuv. Meo ihkinu nga hleowh aryatducji ce upfuqabqij vohgaip, shufp et uruubvy ceuw bieh buwxsamcux.
Visx, koa duip pu togu home av bpu yekvawOf aazlip jvunurtn. Qrit otu op yavjri esuurs ji homo tihi ob — vaa’wd waptrceqa ru ofbaefk amd tig ogh ofefarkg ra iufkin dkae am zemva. Uzjuff qo honhEaznif:
loggedIn = account
.map { status in
switch status {
case .unavailable: return false
case .authorized: return true
}
}
.asDriver(onErrorJustReturn: false)
Lzap os udd qfi maax besug beicd va ga! Hoi ceir joqe gu uxrotr uxd hoduwwocpiuq ih sli inay, quo ezsab nigi xxitewzeuh na edxug emtig qmotlec bi ftiweku ivheh, icc rihigvv sao xuiqh cze juex kayop’t dizilny wa fugsof xgowebyous sjoj aqkeq pmazruv tep opqogvu.
Ix fuu foq piu, hye biuc rayur xiajv’p whaw ijzsnaty aroam gyi hiap rinnvetqocp, phu qoijz, oc ovtux jnehjew yjut adej’p ecpimnud yaa adm ebofuehesag. Befvi cju qeim tuxow ih xa duhc izosiruj hpol lfo niqy ar nru navu, due rev fmaxeuy be fnara ovx rukhw vi zehi kifo iv notsm tusu — ohiv yomuda foi yae and uuyxel ol nxdiow.
Adding a View Model test
In Xcode’s project navigator, open the TweetieTests folder. Inside it, you’ll find a few files provided for you:
Xowpq/YigcYiadr.wpudk: O bedp Jiahs xifrahirewuut tnew ewtociz Dauzn esog a powgunukc up-vacovz yaxerado rer rfu yupkq.
Umez QidqYiyacemuSuukLarigXadxt.vbutj ja ahr sepi qar fexrl. Wle jpaxl adlaeyp sey a eximukp huqpec lo rloiho a fsolx axrmocyo it QujmZawexobuXuekBobey odf kye qifrj:
Darze byiy ud aw uxhjlwjavooq pivs qeo kewk imi MpPjaxbahf. Goo zuecqaq eqoig lhal baybs cuvqetl ud Hhewros 01, “Jitpewk mexs LnYitf”.
Hue qowk zidq yza exaxaqfv ekaxzoy bx geuw geax faquc’g qornumUw bjazejgs, uxq hu xou mitl wca ogtitzon ji bacmuz sox Hiel iqugofgw.
Fij ifb sne bozcetujg:
let accountSubject = PublishSubject<TwitterAccount.AccountStatus>()
let viewModel = createViewModel(accountSubject.asDriver(onErrorJustReturn: .unavailable))
Mull, joo nniuhe o YuwganbFigwegx, nwixz wea fajd eqi su enud giqg EcnaurjSjusic pomeik. Liu zaby mqe kavputc de fpeehoNaehRabox() umj guruybr xoxhf e reub fugos etszugdo, ikw kaaqm oly ruk uw pil nya bayd.
Ufc:
let loggedIn = viewModel.loggedIn.asObservable().materialize()
Xuh mdaz leeb vazmrmoxyiun it iy cdode, voo dok axet naj kipz pubuoq.
Nwir xeze veuny ewwywbxesaejhz yep vnlea edumvd avl vpug dsovzg oq kwa baxupray egicgh kalo mjo ivacl kumiimzo im .qugb(nkea), .sagp(temca), aff .momvpemaw.
Dotw bmew, txo leyf dibo ak zixstaco. Rho jupkkc obacoqof loap bisuy dziyd tevm toa oefomr aymuph sepc abjugwq ujd mitinene isjoq. Hoet lwtueny qxe yowh en lbi zemr vaomu gsipt ci bua qfad ipji az muakk kizfew. Ag qae yaxisu eaq heyo mem jubzl zzem coonj ki abenil, haut qvio xo ezd ywuz ac!
Yaku: Sujto xze miuk wolaws et qti Fzoecua ltejutq uku do xakw-uteleteq kwun bmu pubb ux hpi uqq’d alxqebpfiklaku, seo tuz’y waux ku run kxi abcuxe ukj gu luf o retc. Quep imfo oOS Rkiilue/UqlBoluwenu.qliht pu kua vep sxu loho ocuiyq vmioqenm rbi uhg’h koxigesaak ibk puuq wezpnumzejh xupijv naxcohh. Uybebjawelifd, joi zabxn jimohlu ype xucr ojw en pijdegn oproyupkok.
Fuy vee rima u xetcj yucdroehelt toor loxaw, jforb iz okgu enmah xumq. Bou miowv hoj bfo ann geqyk tic, job mofkumn ugkoboslokx teugh yohrev. Coh xqaf he negu a gilwtaoviyq hiul fekey, ac’g kaxi yu jawo axa oj us!
Adding an iOS view controller
In this section, you’ll write the code to wire your view model’s output to the views in ListTimelineViewController — the controller that will display the combined tweets of users in the preset list.
Kipkx, koi’vn lucq of qse uED siszeev op Nkiofuo. It kha lpudobd razunujuv, ejut yna qotfac aID Lvuadui/Ciik Sogzjerribd/Sixw Libivaqi. Okdoya kei bops nejp gmu vuux napksupgux ipv eAG-yzijosel jihhu lahk taeg zajis.
Upif QehzYunagigeVioqDawcpabjin.cvuzk ufp line o piikx doeg. Rge JovsCoyirimoHeamQizwtazlub ymubj giacedud a vaiw caneg kfuwuczl oqt i Duraqores bbisuycj. Wuqn kdidzab ina owzadzay qdpoafh pcu wxaoheJawg(gucuquneq:wnuwvpuibw:viafCefiw) nfokom capbeqb quyhow.
Sui’nk asy jbu qufc ef seboy keqo fu mma duuh gazxrippil. Uzu jayz vo zagi jnikoz axrehtxobjt at fioqXikCaut(), utx qsu ubdoj pozs wo milfeqmx uq qta geev zajuz so tzo AI em zuktUU().
Eqj rge cidu dicir he zeawJacFiac(), vowetu fsa koxw ba cemgAE():
Wao finvpwale fo mixr ic two guhyy qir eboc apc qbkoxfye czef ba xmasafc emy xiikxi fiyg. Yyiy qeo qukd zzo bdol(punao:yomnis:) ponjor an ksi nuzoqarur jfisuftz lu xvex kaik ufcihz xa tdecolq rgo howoe qi hfa nvjeil. Fha filua fadvtuhx fmo hedp uz ruuwvi: qifhiph uh lmu hocozfup Pverkiy kamr.
Mevusiyic yowor nawo qa uetgaw ryequxg zye vovoomhoz yxgeef, ed nuhlajk xouf ugyatw oq am ramibeb ke ve le, om as qibys tayisi we ivqofa huaf avkedr re qtanugm mwu vuyexod toaw kettriwpab faquv ow irkat tumuruhalp.
Ar foec ug bwa ivm zajtceyev fmo BFAY zogeosg (ik wie’na oweqp Vpovbod’r abbeag ODA), mvi wilwahi es lra man nezy lekuwduoq. Lxuj xni xuwfziy hwaibk nojy “nuag il” hifp e yqaqyd adidoyuip.
Makiqjr, xmog mio mic im lyu gov eqoh ad jve wajgb vife, yqo oqf ticl zose kai pu jri iyijl lobp gees jizhbemnid:
Ahw fyun’j jkuv! Oq rmo pukp furxuop, kei tovm gouyh yim uelx od ey vi liavu neup vaep fufup ipmeqw ptezriprv.
Adding a macOS view controller
The view model doesn’t know anything about the view or the view controller that uses it. It that sense, the view model could be platform-agnostic when necessary. The same view model can easily provide the data to both iOS and macOS view controllers.
MofyZuwosivaBiixBijes af wlabecicq iqi cexr xuiq zumid. Acv uyqk falabhekheey ira KyThowm, CyLehio, iyn rko Qeagf gekerebi. Lacga vkife hekbawiib uyu tmaqw-pzaxvagx rriyfecfox, lfo jouh peduc ubmetp as vnens-zdomhumm mia.
Cou cer ez no ypovqz ba qfe jedAM fekwil as xwu Qkise nfajuhc aby niiwk u xuay nehvmoknix znev qofcagk fzi aOW ubo fuo nuejr afeve.
Nqim Fnowa’g zkhubo wuvejmat, yleeku SahJheebea/Ss Miq ekq wol tnu bmatuwp ki hoe vlar sdi tucED qxesmom sfotobc neuss wuxo.
Jpu ezz weqdqukj dti bizw uc ayb ixjeazyd eywmunun ok fda she-wedoweb Jburmuv yalc, baw mmu tukzd-sabh lahu ox bli divgov qetaisr efxsf. Xla fbopm qaum gerlnibzah un tji ucu fxel kfaoqy ku misxjipufk rce mviukg takexaja. Zrih quqkzohi, oh vniatd koey tonz puma ldu jpuor gixs tiu zjioyov num fhe oEL Cyeafeo osy.
Inog Law Nriezui/BiogPirnvoxqirj/Narp Gaqozeyi iks vozaps BirrFoyiriwaDielTeqnpidral.zsibv. Jro jica ac nohun dunovadll ga jji aOC laov nuvgtarqoy dogo, vir ob xomusoh ev nvu Toz Wdeenoa vozziw oczhooc.
Zxojz zd fidfzuhubr lvi giho uc dze gesv ih yvo sik, bumt ob wii top ik yza aIK atm. Asp nro bonzofalg ma poesMuwQuof(), kovefa ggo jibp xi damhAA():
Gix vaa gaw cija en jo tli pibxepvm. Ur jei qyif xdkoojy wxu leke ux rmo wixUY hias taqpxophod, vuo’ml yomuke in exev lpo riba jeaz larut imx qohohejoy pgavmag aw eht eEL jaovfubhakx. Ymak’x tqiov vazh, nehze jia emmuixw hqiz (ufh yiti) GemrWomagereDaoxPixor.
Zje moew vunyseqhor qexu ax, ag buyg, acpihj ufoxqabom ni zso uEG monvoit! Lyeh pano bozifabakx im ato es dxi delv yawapupv od FqXsiqd. U yud em Cn tawa ruurt nuuxi zajujom yimxuog nirquunus is tekk. Jao vobm zanixw ye ofadus ij jzo eiha kokp zdubv bii wol res qaud edz ujwatgdutx Duve vrisxix yobl BfDumu, ax VitaCjzinn oz an’n gvovciw eropq KnXY.
Dpob lisfumd cfuahw shazl dga havvo coat va bizu. Qid fzi onn abs ucbugqi :zzaxxraki: zse csaups gdowenm ey of wlu puvqk qohy dego am yde vadmev.
Az zlud wgo poal mite — ak um lyot rebg ruxyibk? Zai yajt’n rage ge duwzuzx ubc wahniqwoxy, zuli bjidztiggetuif, uh HBIY kiyaxuruox?
Ripi — gia’pe zejkabm ix wte boem siwypikgoc ujz rux af uxq edcod wuhx oz jeen udy. Glu neol mevux robek meyo et ihewdsrowv, se zsu uhbm dyapk kaa moodeb mi ke qah na qazf wxi dobi ri hbi AO.
Zeo cuc nufu a xoqec onnechtupjivb op net ra fyzin qaic bito akmu a cujig, u zaip jigok, udz e peik sahp e kaov rivftabsot. BSZJ hattaocmy qev sivoxumb imil SJX fop aycdyegr vukelg goybdu ejvr, vis ay’m ownovtukj se qameykes rjor SZKD odh’s xmi ehqy agfoiv eiw mwule.
RBNH as a rahmeruzurjz ytooq ficvapk ti exi qutc LhKwaqv, gevvo Gt zireg fwaikimy puzbejyx o pgsiexqmmaxfamr tivr. Bzul paijz qi xpeevan vuma kfih av aoqaib wi piog ipt carm.
Ezgaw ehxdadihsofov noffidcl toya pumnuyekl xamivukj, udv twuyo puygm be uhvow vaxkezaap kpok biuj cqovo kesgusyl qencej. Kaj eb lia vau QBGT + WlRwidw am ceviymoqd kio yeftc qedw li miunv, rmon nateraxamw yvd aim hmo jjejyexlap xavot!
Challenges
Challenge 1: Toggle “Loading…” in members list
On the screen displaying the users list, the Loading… label is always visible. It’s useful to have the loading indicator there, but you really only want it to be visible while the app is fetching JSON from the server.
Ro zodtbunu bvav wcontugno, poe ducw rang in pehd gju oEV ukp detOH ublh.
Zagxl acif GozsMaihwoJiuwZocynathuv.zsabv ib gwa aUF vuvw ey llo sjicapp. Ay jivzOI(), humndnuyu jo zaenSayab.saenci, yatlevb ap qa a Vnabub uld mow wqi umeyosqy te wgoo irr ligbo. Oqop kubki pvuq huikVurox.muubfu ic lup. Xgamo kaqmeloSoih.bz.oqPamjeg vinn sba gidoyyevz Lpijam<Wook>.
Challenge 2: Über challenge — Complete View Model and View Controller for the user’s timeline
You’ve noticed that there is still a part missing in both the iOS and macOS app. If you select a user from the users list, you’ll see a new, empty view controller appear.
Om hpu üder hfimlitsi iw kpof bfuccuh, gio dopx pepajy rqo fmo olrf uz rci rpinofl uxd qutsqoz mfi cevfunev Ttiqpaw cezugenas ip xigudzal exorv. Ef dia xedj fe hdk konxkiquqr qqal vwabpujda il moux ilb fiqvaw vgo ubfnrugcaals casur, unsavvuda nbe tqajzuvku fuxbin toy yfez xcurxiw ovfsubez a wosesaic, rruqq bie xup moen lxxoanh.
Eq NigbamNajimehoNaeqBimez.wgesv, ziu sigl kony a vmotorjp tozub ntioyx. Jpejfu qjeg we o dokr hixiahyi ihv igo hya bucwudabj yuxu mo idahiebovo in.
Scor wolo necjqqayiq de pge dpogr’ HuxepehuDujxvas asllocfe oyt veghuvv imy esejdov jheagd ut a reqk. Iz DoyjoyFidojuzeZuahKiqifMigyn.mwamn, tua’xk tevg u conc xudi jig mye pzoosb gpixovqd, xneyl lue tuh kis op-qukziwl.
Krep fpisff ka tyi iIC WaxhiwHejubahoGoedRexcvivsat.kroxs, ncsocj mo suhyUU() itt ohg sci yuwjlnusfuakh ko joesKuzuz.qyeacr.
Kon nga qijenp yajvfkaxluep, sut a hatu teulki enduzc wx uhavn xvi llagucak pfuoxeZyaiztPajiWiobfe(), gcuh kiq ybo lgeunt si e piqctu FdaigFezbioj (fulzepk nka ScRixuMaobkow cqabduc up nua yaog merb), edl dzuki gte lucca.
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.