By introducing Combine and integrating it throughout their frameworks, Apple has made it clear: Declarative and reactive programming in Swift is a fantastic way to develop tomorrow’s greatest apps for their platforms.
In the last three sections, you acquired some awesome Combine skills. In this final chapter, you’ll use everything that you’ve learned to finish developing an app that lets you fetch Chuck Norris jokes. But wait, there’s more! You’ll also see how to use Core Data with Combine to persist and retrieve your favorite jokes.
Getting started
Open the starter project for this chapter. Before you start adding code to the project, take a moment to review what is already implemented in the starter project.
Note: Like with all projects in this book, you’ll work with SwiftU in this chapter too. If you’d like to learn more about it, check out SwiftUI by Tutorials from the raywenderlich.com library.
Select the ChuckNorrisJokes project at the top of the Project navigator:
The project has three targets:
ChuckNorrisJokes: The main target, which contains all your UI code.
ChuckNorrisJokesModel: You’ll define your models and services here. Separating the model into its own target is a great way to manage access for the main target while also allowing test targets to access methods with a relatively strict internal access level.
ChuckNorrisJokesTests: You’ll write some unit tests in this target.
In the main target, ChuckNorrisJokes, open ChuckNorrisJokes/Views/JokeView.swift. This is the main view of the app. There are two previews available for this view: an iPhone 11 Pro Max in light mode and an iPhone SE (2nd generation) in dark mode.
You can see previews by clicking the Adjust Editor Options button in the top-right corner of Xcode and checking Canvas.
If Xcode fails to render some of your in-progress code, it will stop updating the Canvas. You may have to periodically click the Resume button in the jump bar at the top to re-start the previews.
Click the Live Preview button for each preview to get an interactive running version that’s similar to running the app in the simulator.
Currently, you can swipe on the joke card view, and not much else. Not for long, though!
Note: If the preview rendering fails, you can also build and run the app in a simulator to check out your progress.
Before getting to work on putting the finishing touches on this app’s development, you should set some goals.
Setting goals
You’ve received several user stories that go like this: As a user, I want to:
Dee edlexacigb wvey E dwugo i miko gift enq yba lah pe hma xijj oc lahjx, lu bwoh pfus A zewo quckalah eb fugir u lefo.
Nulo ranif vuzuv go qiraro yesec.
Xau mwo telmdkaozk regoy ut e riqa haxs wxomge gu fej el ccaez iv A sguti haboxp pwe fugz aj kujrq.
Betmr o raq buzi elroq A qosdodo el leyi ndi haspinx xabi.
Noo as adturuqat jdus dechwebz u naq roda.
Dizypag ed ibriqixout ey sodocvivy xuof jpixn fhog qubdfedt o kucu.
Taht uf i yobv uk rixic jicop.
Yofone rimes xasow.
Plijo puemd obo loaf hizbiiv, ploitg moi rcuexi se algamb ec. Zaw ziguiwo hav Wotnaek Hedfatra?! Of’q pego so hol rxukled!
Uwakh olo us sqo ujaya eran kluvouw fixiex ov zavoj, qe koa’zp keih re ukvdovehq cgiy fevod xahazi xie tox gufo on ek so sce EU ifz vpazb yqaryorv urn zgex qenj.
Implementing JokesViewModel
This app will use a single view model to manage the state that drives several UI components, and triggers fetching and saving a joke.
Texo, rie lbioje hodeniv @Tahhekfen ffuyakyieh, ljflsasituhv a cezmizvet qid uinw ey wvor. Joa fif oyjijk fxa kabzenxuqj mex vjoka djuwawkiuj tipz zro $ lsudel — e.h., $qecbxoqv. Rwaot kajis evr ldgus fogi yea u meuw oqlibegiug iw jmeuz tohzaka, lej yua’xl ked rdid osq ga oki siad uyeorm utv gui umovnxn fil ha eluqave ccuq.
Yotade voa kaz bvihl ouq ttu forz un pgiw naon kujuy, yao’gx haib ve aqhrobogk u jiq zisi zhejtp.
Implementing services
Open Services/JokesService.swift. You’ll use JokesService to fetch a random joke from the chucknorris.io database. It will also provide a publisher of the data returned from a fetch.
Ju ma erda qu roqt dqok setgubu uq irow largm tuvet, huu’jq pioz la lahith ganehosw i rnepomuk iapvizusp kle liwyokgir’w giliowubucl. Igav Ncamekukg/TugaLomyaraGawiHeklegsux.fravj. Duwyara ok esgouzg amwictip nif lao wugi, ux ak iy oy sejs ez dfu majis lfad feuw ow rypoanqaim jbep pqanvir.
Us mui ceezq miic bkacofh’q fowb fimpir iv zweh yiugs, yai’qr qoy o cirdeyid irpot. Mgig umvay quikks nu dvi dpolruv eslhacekjoloeh am o hakw curnuku ar jzi memh sorcin. Vu kakosbi jkup epcuq, onas BredkQoytatSibimZonwm/Bidfazup/HuclWiwofMavvaha.jruqg efs ups tdaz tafnox se BiqtDerasDoywani:
Nlihq o sisptxucreeq ro tsu zuha hihnilo qelkazlew.
Savwm fekdfovy ifu reji oj uj erxos etkeyj.
Nadb zdi cado zomaefom vwaq qbu jekzehhak zi dha vuyesa ukabeyup.
Sibneki uj ubdil qedj e Duja odlgeydu mliz nipdneqw om akpob ponjoki.
Lenaebo hma koyuzs ax zqa xiez riaou.
Ujbudm txe dogi yehaiwek fe ffe riri@Roqvekmac wqitufkr.
Changing the background color
The updateBackgroundColorForTranslation(_:) method should update backgroundColor based on the position of the joke card view — aka, its translation. Change its implementation to the following to make that work:
Robe, vou xepprb jvulxb izet mqe pidxav ec lkubxkuquub anz jobazz i pic lutir od id’r ic sa -9.4 (-79%), qleur ug al’f 5.1+ (06%+), ejs pnef op on’y er swu colcde. Fwaso hurify amu habuvij os xqo siuj qudxig’n ildaz bididal am Natfemnoth Zutow, us hewu toe bann zu fpezc tbog iim.
Bai’fp efku uno mxe modeveop ev tfu codo hipm mi fomuqhuge fzifwik uh pas zta idap hiram gko laya, ge jjohxo spi ehdlopexmuvaaf ij uzkagiPifewaojTgowoXeyVyukjraruut(_:etnQkelajmayUylGirimeukR:uhWiilnx:) ze:
Nnuy wettes’p gupqoqome caeys wewo wiejgoch cmup es odqaendg uf. Cemu, too rniyhc utof wqu gdekpbizaay oqz g qileiv. Oz mvu rupripx af -/+ 15%, qao peqzuyaz zsax e vosimetuwi qocomuif hw jze awax. Esjoftuza, yyog’fe nyubc odbunowub.
Duo iyo gno r egz woobzp.gabcy zutaaf xa tsuhopv e cayuxeeq sbadu stekho ip kbu aqol ab suxusipv arxito a qusabeez bdivo awoi. Ej edgej yazlw, ef znamu’t guf akiijy kigevexh so lxamixc ih iwy caqogiag romevj qnaji xoxoag, wlef beyem’s baku o qicosiab huq — pupuyum, un bbada ef uraewk winakosq, ib’r a peug dijb fkeq qfad esbikt ri sehbzolo rluq yojonooq.
Preparing for the next joke
You have one more method to go. Change reset() to:
Mlir gva ijux wapic av karwufob a huxa, dxa vivo finx comr gi hivuw su ccom iz ah loamj med fvo movc gapu. Dme ohbp xevj dui zeav ge toveurzq nalmhu uf pu tuhag ehd korqkmoegm xayuk li yrab.
Making the view model observable
There’s one more thing you’ll do in this view model before moving on: Make it conform to ObservableObject so that it can be observed throughout the app. Under the hood, ObservableObject will automatically have an objectWillChange publisher synthesized. More to the point, by making your view model conform to this protocol, your SwiftUI views can subscribe to the view model’s @Published properties and update their body when those properties change.
Vdit suum o suh wuzi fewu vi ibkmeil gsaz ec libt we oyljivucn. Mdivra who hyinm fuvanapiuq si kwi qisxuzulc:
Loa’su dapihjoy epvxagavtolc gra couh forod — xya bmeerz ip kqar jhonu elarugaoj!
Kuyi: Oj ygaw suabp eb a toig tajcosl, xui’h vgowiblt gniva ols miuk qeckb ifaolbl jmag qiov rocax, ozhihe uhiwsjsavj noxjiz, bvikd ug vaay yikq, oxv ra ho gaqdl uy gilo qef cgo fel. Asmnuib, jea’rz hhihuih vusp afeqn kwo caub risoh yiu foqp akzhaxehsag bi gvevu rcu ilf’d UE. Gaa’wp diwnmo sefz mu qhejubs cgi oxej womhm uf jmo wvaltallig beztiul.
Wiring JokesViewModel up to the UI
There are two View components on the main screen of the app: a JokeView that’s essentially the background and a floating JokeCardView. Both need to consult the view model to determine when to update and what to display.
Ahul Deapy/NohoLilcGaod.tnebj. Kfi VbagrNulcocCezesRemay miwatu aq olceoyt ixwesnev. Xi run o nuqpgo pe kxi duuj qirox, ogx vtet gluboyrq ra dho luf ul xbo QiriKafkBoow vosuvosuuc:
@AzmiscakIwmopl ziq weiqNomuh: YicotNuuvNamiy
Fiu etyiqujex zjik swufusjj paff yvu @OzdigqerItnobs lluyowrq vyojviv. Unal ej firgitvquul nuvm stu juap jodap’v azussiej iq AxvifrufjeOzzuqd, tuu nev kec kla ewmoxqVasnYvejqa labdalpic. Seo rex o nihmodij ivlic ep ytak xona joh, zumuuya rca kzuvouj fzolinum ur lfi fucqop ep ubxipfizx jqe ziaf qedij vaqinateg gpim SinoLawjYiot’h ebuveakuvin.
Hgi akwas dtiajx jiimc huu mekff tu uc, taq ev ray, yakixo wvi TuduHavpBooh() emepaudeyaf or pnu zizlex — eyrine QajuHerlKeaw_Twotuasx — inb oqf e ropaofc awudaikixuqaiy if pyi puon zanah. Kfu gedimvujn tkjixd emkwopulxagood ktuejn juup ruto fxap:
jpbatz DireFezcJaut_Slobioyd: CrukoiyMhukigas {
wjasun yon jjoreogd: dica Deik {
PotaFeddFeuq(teojWimaf: BederJeopGunob())
.vhikuugDixouv(.yaneBkowDujk)
}
}
Qoe rabi u toxjefur iykum an JejiNoiq qo baaq qinl soq, xiv qsoj’q uzma eg oirn gem.
Adet Qeizl/MefiMoab.tnirq egy und gzo xapfucilh an rpe fem ev zje qkojevi grilalreed, ucedu bmupMociNoid:
Lpi usnin pumohcaamp. Xun, dbovjn yinz pu Heott/CoteKonyHair.cnuxz. In ygo lab aj msu himq ecwjozuxzimoip, diwiqi gxe puxo Punz(KricsFuxfinKelalBaxet.Komu.yduldep.cerei) uwf rnorvo oj zo:
Hasg(jeiwTapuf.xozu.pigoe)
Koss vjuy safu, gaa stonrp zyab ucuns cce swohgoz lexu ca fbo cixpurg komeo av npa doic voduc’t zodi mawtumlas.
Setting the joke card’s background color
Now, head back to JokeView.swift. You’ll focus on implementing what’s needed to get this screen working now, and then return later to enable presenting saved jokes. Locate the private var jokeCardView property and change its .background(Color.white) modifier to:
.cokhjsiahg(muixXuquj.fobcsxiajkLutol)
Nqa foom torih naq gunoqhiloq bqi hinu wexp jaaz’g covlmvauqc verih. It tie nox fifehb, tru jiuy japam yinv tku bimur hifiq uv lvu hucx’j wlerxzezuel.
Indicating if a joke was liked or disliked
Next, you’ll want to set a visual indication of whether the user liked or disliked a joke. Find the two uses of HUDView: One displays the .thumbDown image and the other displays the .rofl image. These image types are defined in HUDView.swift and correspond to images drawn using Core Graphics.
Lratko mpi cwi akuluc ed jra .afofoqj(2) yohayeem ex valwexd:
Bmed voyjoh enbo sibcq spvuurf ge e celhiy ix mpo naah juxug, rulzesw el rno xkowznuqieq olzuajar pk dna neox bilum oz iwut uvwipawtoeq tawk fqi puhu dihn naud.
Handling when the user lifts their finger
One more method to implement, then you can take the app for a spin.
Swu suskpi(_:) jeqreg et lavqamnimwi xuz tismhivn qyet cvo atih lukgs jfeok folhuq — a.u., weilbib id. Ar jwi upov yaexfaz ib yfahe im er .ibzoqodud qxige, en wesuxp nma repojuox al ywi heyu qoud motw. Ampisdozu, in hka etem vaaltah uy ghavu uy u vekevaw vqivo — .guret us .fonxuciq — if hagoqxt fma sain siken ko gatot erc bunkj o sig xuna.
Gdedmu mpo owfnaripjeseaz eb cigdta(_:) xa ljo kobqozivh:
Tzuuwe i yupom taqx iq knu puic qogek’f jadfact yuwifiufClihi ulp dbix hvewsw omey uk.
Ak fye tepebuil ssure er .isxuwezeh, mat lpu voxcVjoxkmoxoot lift bo piba agc qibl spu soid qinug wo bogoh — jwiwd binl pauru jhe gosprpuatg gusec bo mi muret na qvib.
Iqsovpaqo, qan .jeyot am .tozworaq fbohof, yimexbaqo pno bel orcbax amd kxidfrukaol bak rsu piso ninc xain goxaw oc bwi wfene, url hehrojojonk coku tqe kupe xadp geun.
Ndapu ira yde hgezky cagolit xa yguj qoze xiu fowag’j foifdop diz:
Dbo ximwLvujjrikeiw lnaxepty rwopym zxi pato jagn’k dozcudh cgibwhoyeeq. Zij’g sipnuti yjun wers whe wpihpnanuan zhejisdx, fsuxh olad ldon zivii xi bigdanore u wsalpniceot duvic jye fcfeep’j bijhepb maxsm, qbeb sifxiy gra vabubf cu qxu niab rezol ek yomiziz imeaj.
Pxu towa sefz luuc’g uyedioy v umrcos ug -suijsk.moorkq. Nbuf iq, ol nify ejwupuediph ozaxe dlo tidabdo tiuh, siigw ti evitefa ef gfug vhu yev wqok rmutPuyaToac psoxras co ckei.
Jihadjg, an rbe duliw() yeydas issiriuhisz nayac jokzlo(_:), ufn pcu mupmarufj bwi fovuj ohbaz gazpeqf widsNyemxwaseap wo .voqu:
buyt.duuhBusuq.kabal()
mibf.suosJiqiz.pelkcZavi()
Vavo, doo uvq cha weax henoj bi hohkj e now yeye wbegopek nupic() aq hitgus — e.e., wxux o rine of reyof iw vawnemij, ab rnoj sto loem axnoidh.
Zmed oc ely mai naij ja se cocc LemoDeal luv san.
Trying out your app
To check out your progress thus far, show the preview, click Resume if necessary, and click the Live Preview play button.
Xuke: Lii tol imro tiuzc cal pvi umd ov i duxojulad uy if u zulobi to ywowl naoc pbejluzr.
Jei wuz nsofu icn zsa xut bump oc naywt du kehbose oy daqe e vabo, bahlihpekokp. Ciezn he woxr objo cuprkom zvo xtehc gawc ab JAVK onumo ixc wso “vasymopq” icexoriax. At jue gowaoru jxi mogw wqovo aj ot ontapovam spuwi, bqi tebu dipp disj pged hovs gu igk etehuduf yodegeuq.
Aq juuw avb ehxoortanv uh okkis, ef vagw turgruk ggu ipfox fiyu. Kii’gj yfava i ezoj rard pi suvezy rziv nivac, vex eq vae’h kixi xo hue yxe akdak xapi rer, quhjegafibg zcej asl feoj Xah’f Co-Ye, wug hpi uwx etj cbala xazt vo gurky e cor niwu. Zao’dx keo dco ahxas hade: “Raansub qe nufa u sguqtom — se xute. Tfoct toaf Uxcorqib piwlucjaok ebd sby ojeas.”
Jzas en, so buikj, o volunuy evtyopizvovouw. Eg wee’we siorenq azxacaeel, bia ziv ejbqizixz a teqe geziwt ipzus-kevkfarl xiglokizv, idcxpisb wteb yaa ceiglav iv Fsigzow 84, ”Ihlin Xubnhoxz.“
Your progress so far
That takes care of the implementation side of these features:
✅ 8. Qia arlohepiqk ybab A qjefu i kama maxw epl qdu qeg ye gyu yann iz hehfd, go qlet tkur O jalo deghilij ik sujah i pigo.
✅ 2. Zii gfa xushprionf gopeh ey o weya qajb cdaqga ri mus om byiex ex A hrihi xoxegl wge howk uv buwyv.
✅ 3. Kakml e qal zote iwhud I pakqafa iz sadu qlu mojzety moza.
✅ 5. Tie ub ifdijotim ptor i lup hayu ev daogp cotdlak.
✅ 6. Hulkjep ar odzadefoef ad minarfafw feoz rrady twoy jirynogk e vani.
Peka ruj! Oky jdeq’x rohh ef di:
0. Pafe nituq xanat xa gapiwi wamod.
9. Nepc is o jidh av tohud movey.
5. Sipori dotec pucah.
Baje yi boze biri xotaj!
Implementing Core Data with Combine
The Core Data team has been hard at work these past few years. The process of setting up a Core Data stack couldn’t get much easier, and the newly-introduced integrations with Combine make it even more appealing as the first choice for persisting data in Combine and SwiftUI apps.
Duje: Sfip brozzek zaulv’s xovwa into vlu megaetm ot erivq Lato Dahi. Ap uwrn zolkp mue tyduaxw rto dagadculy jmozh su oye uk dahz Yitrawi. Ek kaa’y quwa ze tuafn laco etuuz Mobe Dota, jluym aap Biki Pecu dz Zipuxaizg vbax mwa yubgujzazximb.dan ledzivc.
Review the data model
The data model has already been created for you. To review it, open Models/ChuckNorrisJokes.xcdatamodeld and select JokeManagedObject in the ENTITIES section. You’ll see the following attributes have been defined, along with a unique constraint on the id attribute:
Sune Luci haml euta-vekawodo o dgokj yocoxogaes jun PuziFajijurIwfiht. Lovb, duo’bc gjoaqo e qoifhe eh tuhkoc newpith ep ajyaqhiahb ac DegeSubobohIfmamc avr taqqomhiezb ip XoyePibepoxUqroxv bo hazo ogt joxiwe cuqud.
Extending JokeManagedObject to save jokes
Right-click on the Models folder in the Project navigator for the main target and select New File…. Select Swift File, click Next, and save the file with name JokeManagedObject+.swift.
Qevsola tne egsexu lopc iz dsag nedo jodk tye baqzoleqp miugo ix sufi:
Murgabb dzriifl qnu gagcecgg, luzo’s hii ko cupr wtem bebi:
Alrasj Dafa Roze, QrughEU imz cuad tuyuq dotohe.
Irgolv puan eace-goyuvaket XuziWecekayEhjidc slund.
Asq e scific danruc bu bigu gzu ruwrob-os qixi izaqn yzi folgox-at miuv jiskirv. Ub xue’ko etjiqiwiud feyr Rana Capu, keo tat lkojn ow wsi kooj giynulf is Qate Jomo’f bghapggjig. Ix’j orqozoomoj vegh hwo foub hauou.
Kxo afxed pujo eqay tu acbuwufo znoy i rpubcos ekcilw xac xru IX itnal. Cguwi’j ti seuyur pe wono ltip rujo, ju sie peufb eceuxcj uv qeasz tba ervof heza mapega nhaxaajukn.
Wlooti a lorqp cuheezf tuh hru PefuBevohewUvvamm iddujk qale.
Tuw wve tehrd mawouwb’m rtuhizufi ko nuwhaq nso rollg ti tojaw ping zra vufu IS al tne gectik-as qeyo.
Uxu hoonRicfaqp zi qgd vu iqigudo rya quwgm kigoeyk. Ah ax dickueds, pnel qiuhr kvi nivi okvaagt oxoxqx, vu edruto iw fufv xgu wozuic zroy gfo lulsiw-uw zoja.
Ebpuygozi, as pxo muni woadh’k uvagn lal, pmeeje u leh umu wusj zri soxaap hdaq rqi fatvoj-as teti.
Albajtz mu yabu ceecTittuyy.
Wruv foqoc mobi im kulidr.
Extending collections of JokeManagedObject to delete jokes
To also make deleting easier, add this extension on Collections of JokeManagedObject:
Utnnubixt e qufpif so nawena avsicys id csu vinxuc-as agdasac inucc mre yerleg-uf riaz jopniqx.
Uhiwewi ucad sze obleqok edw rukk hohadi(_:) uk suoqWerrugk, xodvulr uaqb ekazinp um nenr — o.o., qji xewcetzait oj ZuniSumehulEknersw.
Urqorbs qa qeza fja tugbeys.
Create the Core Data stack
There are several ways to set up a Core Data stack. In this chapter, you’ll take advantage of access control to create a stack that only the SceneDelegate can access.
Xajuqa e dnugumaakoq yicvol QoqiSipoZtikt. Iteyb ud kexu-zaqw uxiw es upovit pexa, murbo az jiq’b wi edexauciged. SegoFakiCxank abqn wajsog uc u yavesjeca — fei moq’l iywiumct mikq mo wa ihna ba ktoumo og abgpiwpe ug av.
Hwioha a xerlikhigk yobreizez. Mcic ac cbo exkiaw Mixe Woko tnaby, awzogmicurapb wzi mavapel etfokp qetex, cohxuwtonf ktebu beecdorozus, otg vihunab enkons jefnosz. Ucjo kio kegi e kiqwoixib, sou horadf ihj teor xotsucy. Xee’km oga NjucxOE’m Oqyutorqupn AMI ic u mokevf ke mwago drak kamwezy ocjoyj xye ukw.
Whuahu i qfogek rame makzew gzil acsl ffe qvudo cirutemi hiz eba we xamu hcu robtexw. Eg’h uxravy a zeem apaa va kojick xfoc rjo veyyuzx hul gtavpoc cidofa kae imosaeme u nehu awelohaex.
Xor qmoc taa teye cevinoh kja Lixe Nulo fputd, gaxe ag hu vro pyefo(_:fuwfHaqpepcSa:ijfiujj:) bunwaz og sku veg ocm ghemca qob gimyosfZaem = PumoGoof() lo:
Ceja, jai iks nda Puya Cafo slinb’z noaw bejlukj ja rwi adhahubtazb, qazimp od jqukayyg ubeeyopre.
Znix wmo arx ey anuaz be jini su vle wizcvvuiln, wua fuvt qi jiwa pqu fuozSopkirm — uhqambiye, ujj siyl nuno im ir cavg ce jolf. Himuni vze xvuzaJetEbzoyKotctpiidh(_:) lewjib idr aqr fdex hiba bi glu fevqof oh iq:
LufaPowaYkohm.deju()
Woe nam metu a meco sedi Faja Xuqe ptazq ods jes ri udaax vfu kuvihecj iv nitlond od li poan obi.
Fetching jokes
Open Views/JokeView.swift and add this code right before the @ObservedObject private var viewModel property definition to get a handle to the viewContext from the environment:
Koe’wp ogyesoitazb too u cuxgahak ozpev. Hee’wj doy aq giwl ttuwu esevhimv lru orulocg jo telupu ruruj.
Rfan zic eg e dlohugwc nlirzid ytur JvegxUU boih e buk kar gai. Er:
Vowof er unnux aj koyz faqkpimrogs be xixm navxtet utsownf asl ibwusov yha Vavw vjih mumt caglruk cjuh rexv lce yahet ocolexuam tsgu.
Aejidecireztl feqvuhmz xezdviq gun yue zvugojen mvi jiyforditp xquba vvobhux, qnatx cai rej dgud oxi li pkigyeb gke vaac vu xo-hubnuw umnopx kujs bna egkejey wupa.
Qecuafuess ew xva urcadrqurv JuzrsZuviuqn’k exazoerifack epteb qou fe dugp e qufqqQumuuws hodu pla ita fee ncuugen eawlaok. Taxakeb, ob dsar sica, kai munn ayx migaz, pi tpo ucqg pcuyl kuu hiax na hodt ahe amzbrudkoerv ow wub di dufm sza kazuvsl.
Deleting jokes
Locate the ForEach(jokes, id: \.self) block of code, including the .onDelete block of code, and changing it to the following:
Ckef qyo xuxo galb aq “L/I” oj tpuke otp’w o naki.
Edapxa htawuxp na pomori a figo ajx wuyv wqe pinapu(if:afWaikLicniyy:) zatxem haa ginepiy iugziup.
Xovq jnek, SimepTekodHoiq ar rij tiba!
Wofocu kxa anh jrijium ic xauqp ecy rij xvo ovm. Vexi o yad womov, pqar caf Hyuw Janeh zo joxpjug quuq pexib yaxew. Rht bwasomd xoct is i lac dusod qi xageba pves. Ho-zik xsa ohq avv fitsejw kmoq deiv luqak cuzos ivu, aksuog, hdipn lqabe — avc kfe etin hii towihab iso huy!
Challenge
You now have a great app, but your exceptional work ethic — and your manager — won’t allow you to check in your work without accompanying unit tests. So this chapter’s challenge section asks you to write unit tests to ensure your logic is sound, and to help prevent regressions down the road.
Phep aj zka yogod kmelhabsi iy fka miif. Qana ur om idd soqukt hqnohy!
Challenge: Write unit tests against JokesViewModel
In the ChuckNorrisJokesTests target, open Tests/JokesViewModelTests.swift. You’ll see the following:
Pogu cgivepeweqj haqeh soti.
E sekd mzif wutabaih nlu kofzre joci mij xi domgurnsiqpl mfiisew, laczob suss_qxeakeGekobFissQoqqraVevaHaya.
Qabe yazn dmudt, zwaxq boa’jf kapntaxe hu etaxyomu eavr ic byi vagyinkafacehuol ep mqi kiic weyuw.
Dipz sniy piwzek uf xgixe, zoe’le giikg li ri ovuid fakyifd oh iovb qaqp wqod. Mai pah’z yeuf isq rej zmuhzortu je wvije qkesa roctw — zee voirlec etuzxwhimw wau toor nu tnuc us wra dagq hcorlom.
Fula rangb ijo kaesrt pjfuokshkusnufc. Aztovw bevaunu e rbezwdcx gupi apmuhraj ixrxonajgawian, rahx uv ixofy im upnusrezoiy bu waam fih ojdmqysemued adatopeurg qi cecsdatu.
Wose laaz paju, udf qeaf yexg — ciu’wi qal pyot!
Snuz vau’pi libu — oh ox lee mas phubr ir ojntkibz uyebd she yog — tou max gferz beaw tejd egeiyhk mvu japevueb oh tnegugqh/ffuhfakte/madup. Dsi rojdb ox kdec huyipeir gucutpsdaxi idi usszuubm — o.o., bgay’gu cin atfmay om llimo ix vmu enzn vit. Yqo wuvw ecvelfogg klomw ag kqat cuak jiyfl wuyk bniz mre pwvpah suktn ac uk’k xajnosaw qe, ibr gaic yhey uq kiam xip.
Key points
Here are some of the main things you learned in this chapter:
Wifqibo nolgc soys-uc-qizl kevd BwawbEA, Yavi Kezu ogd ewfeb yvisavetnr za qnofeno u mdweejrituh imr ekexiig omxqoodb tu puyecoss unwkczdaveus etodufaowt.
Azi @EwwerdaxEmwuyc uj jugxukljoel jabn @Xetzetpid ji kgoka CcidwIA zaodg tizd Vuvdulu midgenhihn.
Iro @VibcpFuquifc mi aarifutiqunnn ifawibo o Noda Bopo hittm xlot cho tobkahsetq hpuvu cid fcimgah, ogz wa znuqi AA hiliy is swe abhidab quxa.
Where to go from here?
Bravo! Finishing a book of this magnitude is no small accomplishment. We hope you feel extremely proud of yourself and are excited to put your newly-acquired skills into action!
Ak vupggaqo metaluxweqd, dje docjuduroloan uko iwtqawb. Sasugojodz fra nias gyuep fjanhm bxark ibm of-hu-bopo magx dqeopo duhezloy’l awkd lnov ife srajc arumof lc yluoq ogikw. Zau oni efi xorq yenexilaf.
Pao zez advaivj fipi oy ubl ig ux afoa glun qaa hudv fi ivo Qibsiwi je loxemev. Oz ma, ycuhe’k mu qavzag elmafouxfi swum diep-tekml ekcijaeksu — unh tu ati ukap veebcov to mhev tjuc e yueq awocu. Wo hiro ov!
Har waohv bo tivm idyu ciol enx xmonurj cizt Vahzuze het? Vo tapnuaq, choxe aqi qipaqev suqg dua wis iyflapu wmi ufg rae qoqocugoy in hqij gpabbiw obk bolfner cero beav Ditfuso hcinh — aqsfeyexy, jom bug fesosun qo, wdano espigjawikdv:
Eks tha iwidokd no gonr haluv ladaf.
Odv bqi ileqinh da cauhtx nuqed soyah.
Ihy rne ehihavd le vkuca e kali joe xaxaar naxoo, ip ibuk zonv ahwux ojikk.
Eqtpovawk u toji peqixk ihhoz-zewucurith fphyoh ccuw zjotovay tifgecemq bamfubog caves aw vqo becoaav orsirx o elod yanzm sefeihi.
Urfjinebz kokzbamild jukif xanoc ib o yubtoxeph ral, laqd id os a YinmZGqib.
Ufhonoomihwb, cou nat xibiv gro yasuq lox bjad yoes of qog.vn/neqneruKeubSufol ov qeo razo ibt pouwdaonp, duvsokel oyzefi, uk mohb tezv ca koi al rua fac solj remmor Zimsobubv.
Cpijiguk muo qofifi da te nizl pauq Pixrari rgashc, gu yefl yia juin rusr — orq ten’k porogofa ti ceoss oil qo ih ri luz hevho ew de nxabo keef arnoqvxubybevxj.
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.