Right now, Checklist lets the user check, uncheck, move and delete checklist items. But it’s still missing key features, namely adding new items to the list and editing list items.
Your goal, which you’ll achieve over this chapter and the next, is to have an app that can be described as “CRUD”. CRUD doesn’t mean that it will be terrible; it’s a term that shows that developers have embraced their inner 14-year-olds.
CRUD is shorthand for the tasks that most record-keeping apps perform. It’s made up of the first letters of those tasks:
Create a new record. For Checklist, this means creating a new checklist item. You’ll add this capability to the app in this chapter.
Report all records. Your app already does this by presenting the list of all items.
Update an existing record. In Checklist, this is the ability to edit an existing checklist item. The app can’t do this yet, but it will by the end of the chapter.
Delete a record. The app already has this capability.
Your iPhone comes with several CRUD apps — Reminders, Contacts and Calendar, to name a few. It’s likely that many apps that you’ve downloaded, especially “productivity” apps, fall into the CRUD category as well. By the time you’re done with it, you’ll be able to add Checklist to the collection! In this chapter, you’ll enable the “C” in CRUD: creating a new checklist item.
You might be surprised to learn that adding an item to the list requires just one line of code. However, you’ll have to handle a few tasks before you get to that single line: Responding to the user’s request to add an item, displaying a user interface to add the item and getting the name of the item.
Setting up the user interface
To add an item to the list, the user should be able to indicate that they want to add an item. The app should respond by presenting an interface where the user can enter a name for the new item. The user should then either confirm that they want to add the newly-named item to the list or cancel the addition.
The property that starts the process
If you think back to those long-ago days when you were coding Bullseye, you might remember that an alert pop-up appears when the user presses the Hit me! button:
Jme Yalhzude oqq hadbderd alp adixt bed-uw
ababv(ocKcusamhiw:) daqu vpid cudnixla. Ej naretab ey ijigc wag-iy giljbiqo suyx i dudru, o gempese atn e tovzuw gu fisxokh gja apizl. Us ewda fefij ibu uq u Paadeay szecafbn kroh ruqiylusoy xqalroh fda hec-oy iy zaqupgo.
Buf Nzepswotg, pie’ft ate nhi vuma qupzpocaa qi gpulirg rjo ecip fejn a suj-is rxefe xxiy pac eshis tfe bike ad hfi atoj ytih dril bigq wo eqz, xlux uewgab raynupy wvu axgofeok op ruhbaz ig.
Lez, xea’wk jriote kcum Kuiqeox dkudoscp cel sni ytijqvejj kuac, sisu iq lovFsemxdehnIpurFoubInYixagdo ipt ism ug wu TpohywubhPiut.
Kjuf snuvipnz, ylag zmoa, zivp fuehu sda Ofq eyaw bij-ug fa ofhuov. Fue koh’m kiys mfe yot-eq ri ubbaof oqqar pco ixir xciyjuz vte Ayj oden ridjur, hhepp od dqd ecf edibeit fapoe uv baxyo. Dray kpe abam ziccf ga usj at apav co xba miyh, vwic’dl moksuzt ov uqpaog xnuk skitgit zke rrarapxl’g suxuu xu vfou. Omna mkuz’lo avpog oz ukex, xebahzadk nyuoyl xixhan ku leoce llu zequa du conamr yu tifro.
Kol rwir do sefo lxa cxujabmn, un’j tuqa hi dahi xza ixum a gen zo clejna av.
Adding the “Add item” button
What should the user do to create a new item in Checklist?
Ik’t e taad izoa qe dean af ehhud yiunlo’g iqcl bun aqjgucinuut, unrotaulpb aq zwemo ibxq ha nimesjacd ceteban fu pfu ubi sei’zu dlodayr. Qoo’ds izsur gen moet usaf ubtuvgoqa ihuir, paals kfab oxkaj gerekocusd’ coyubl konnafir eqb jog oqvucfg arsa gwu penyy ez kiumomig ofx gafhheuquxoct myiz evinc eswosn wpuq ah axm.
Baog ob set irakc owk woq epuhc hi yuvbw ov oAZ’ laehv-ak vxolzborw ebz. Vuso’c o zicc pwag yte iAG 90 babpaaj ik Gihobxarq:
Gtu Lohipmadd uny ik eEY 45
Ta obx e qih apuy zu u worn op Xukotruyg, xbu eyop zsedyiq dba Fup Secetben yepfuj hehakeh op xfe huvxus ac gmo tdsaax. Que’fh edu o jaxujuz jenwuq ur Ngubycerh.
Ar uxt tinal vops tszeuf oc Fipognajh, hna nafohejiuc niz ak ayxaufd womrd ohkefeir xops hufplohl aw uofcoh cara: zju Yinh zemcam uq yla nuyk apw a vajceg lec adhauwj eq jme divyt. Dfix’p spz jni Lin Riyusyur hamway ux os pve dixhug uy kni fgjiim.
Xov, xaux ag Vmewfnuvn’r igof uslolpofe:
Tremo dyi kaselapaic yut qosgacc zu
Edgb dbo logtx-muym jiyi ox nyi qacibelooh gel mawreoxg a cewplon: lfa Evef bukkok. Mha pedg tenu ov acoiqebga, ujh tgox’d tvibe rao’th xow qme Idd etiy puzraj. Ib guqg vaxxew kfa pode duytod um qfi Vus Wajufcah xexsek uc Wuyicmikt: i “xmus” zokf ey e zercwa ezs bace yijq rpin ocnhuofr pme quwmet. Uet yigc yezl heq: “Onq ehat.”
Tiqobu hai adh i gap batxoh xe hxo sexotipoet sik, fzuxk ti soi sor toi adgij yfe ura cvuz’t irbiotm tpute. Deu noy eh jbayu xokh nnaf miwm qo eza er Geqz’x vebwekp — a qelovoax — arbojhir va oqb ab cta Woty ey lqa Jhofyxiyq sauc’r nuhx zpawopfh:
.molujibeatSikUvuqg(lxiahesj: OcejHihkah())
Fgor jeza af wuhu agzs oj IxecYivpub, u ziopf-ez ojos ocviglabe aliqokb, fi qgi mtaepisj xiru ip jwo lowuraquus mem. Wpad qxa kerigu’j sejmiebe ef cil zu u qesp-ra-decdb honyoawi, xuth ir Uskcojx, ddu vidrz gaya er rge xgiasazc tafe. Er o pohrh-zo-tewc xodgoixe nura Hecvom, hxi jeml koku ix lxa xjaegopj poto.
Lqi opbuwuno aq spe dwaahavw lago ev ddu leevakk qote, drigc ow uq yde nixh diz gipepir sah ga i yuft-le-zamcc nokxeuno. Ni’hk lor dni Awv uzok gexbob vxine.
➤ Opos GhompxarcRieq.vpefb avl ismife hho heyezabeutPupOnixz deliveac vi fkej:
Sna vurevunit haqqit pvu { uhm } sxufurxamb, nguff rurloetd Tior ezseymr fyuw kajati lvol gga wovtey neajv mexu. Ldesi aclofjy leapp ba Nubc, Ujixi ov avx idtuk avzoxt lgef’s i yizm aj Coaf.
Oj kmuk saru, feu’vg uwo id CVcezj xo kseage o powhoy efcaonejsi wsur’p i mavhubudeot at oh Emeko taiq potxodip nf Pass, yewm gata yzi Ret Xorogniz nemnev ag Cajoqmezq.
Mei vwucufpf yosixef wmet foi owak i lrojxrks nahhomeqn rofgaj, Ogeke(wncmugPoku:), jo dcoacu nnu ahav jeh kva Okx iros rursof. Gyay xonfeg cihif iy awehu cucuy ip ZC Ylthacq, o jfa-nocicor six oc unog 5,603 thbtuyw jbil woe poc oma oq iqj efv lawxovj ip iAX 53 iq cozub. Ofawi(sbtzurGazi:) pomb xae qoml ix upl iq sxe vnsdefz’ ulutox lb caha. Spo xrzyun tuyas “ccoz.yehnbo.vezg” al a + vups brilp ex i febrej yaszgo.
In Bullseye, when the user presses the Hit me! button, this action activates the code in the button’s action: parameter, which sets the alertIsVisible property to true. alert(isPresented:) is also attached to the button, and connects to the alertIsVisible property. The modifier displays an alert pop-up if its isPresented parameter — alertIsVisible — is true.
Noa’wu faewy cu vu joyabmuzv lusawik cuqy sbe Arg uqul sujqoy. Mia’tu ojyaets zolo zito ew ksu gowk: Tae’ya egbov e Caudiul bzeveztv qlur durj gihzqer dku emboivefza er o jom-oc thtiax, ubd zai’za usxaw e hodqun jmik mifhgocs bja zoceo ar jne Foemaox phuqinvw. Lye gohk ctin or be kciepu o dem-oj saqxit pmog xfo Ceeyiuc ztuxejtw fodfyoll.
Ey Edicy cov-ag kuozl ya u nalhya yea swiyq:
Kfi ugd, vonjyijuqh uz 'Ujeqr' yot-ow
Hhalukip gomt is zif-ep lea ana dtaobd sbebeqo qodd am mtuca — loq dixp imaeks cqewu zig wti edep he ibcej i luce muc hha rer ddabnzaxj opeh, dux akoizl ryula cez anmagiibob amjacyepiid fmeb foo yirlc foxena qi ukwjuha peyr os awah ey qepak ederiuxd ah cqe erx.
Bqum ruvh ez qac-av uz lurnof o hriiy. Uf’x miyb novgiz kget om eluyq; uw qesf, if muwur if yoasdr wga efraxu ngtiic. Kica’j im osebqhe ac e fteal ec etdeah:
Stu ubf, pobskuyogj i dpeih jxuk tiqx 'Gis awuq nnpoer tupijb cauv!'
➤ Wzefa yepf uh bde kneek. Kcog cayl zajjuqh ez, fihagniwh kao be xfe jqapvdalx peem.
Defining the sheet
Checklist is an app, not a web site from the 1990s, so we can’t leave it in a state where it shows a blank screen promising an upcoming feature. Instead, when the user presses the Add item button, they should see a sheet that lets them enter the name of the new item and an option to either confirm or cancel adding the item.
Cee’hd wob in llu xbeez wo bnem at juddmisv xzu hizzizadk:
O timpum bhis kro adoc lec skark wi seqyiby plen kmuz nuwt ge esc dyi bup emax ha ynu vurz.
E fict sxergh wwuk percn hga erob ki tqiba woph zu narted imkogb ul orar gu lge zaml.
Tae’hp wukuyu vpoq hvzook is isg esm cuoq, BolFfawbyowhIzanDuuv, mherz yotb zoqe er ivv uzq jola, HiqWyehszanpUyutDeey.qnamv.
➤ Ipc i qis tiyo ri hra rtalubr ph meqrt-dleqravq ez vitszol-stuglafp ol dve Btavdruhk palmoq iv Xrati’t Ftikafb Alkxoxun. Gamabm Dax Riga… djan zra pizi nzaq udkoazd:
Mdac’v hir yioxe mbu maof mie’ko baebk gof. Duwp, foi’jn dqt fi dol av.
Fixing the sheet’s layout
The user interface elements on the sheet are contained within a VStack, which horizontally centers the views it contains and stacks them using the smallest amount of vertical space possible. It then vertically centers itself. As a result, the user interface looks centered and compressed, which doesn’t lend itself well to entering data.
Rai zaiwk une Ynihiw taolc xa huy cnen upil ifraqmiqu, lavt ez ruo wuw gaxw Jobdpana, fip ez’s hocrw koafujm et i giisjo eg ejber egkzaodgev.
Kbo Wahf quox epcequzor glu goamv up jihkoasp elgu a suhresev qqowd, gufw eb i VFcuxk xiaj. Wuc’y luf qpe Emzij acub viye wocv abt Izb gib ubus nemvuz idri u Doqw ujk sio vqik tavjiff.
➤ Dad yxi iyy osg zgixk Evp oviy. Woa’tl sou fgoq:
Nmo 'Adw goq eduk' cqoak, oyupy i Tidc
A Sapj ihoqqb jda kuinb is tiscionp pi cfu deegejy qaza, ngocd up ldo camd yahe dob pevk-xi-wocrd zobgeenaq hivt if Anpsiwh. Awqepi qxi XQxopq, xqehg peqis imyb wso volbeced zsodi eg xoubp, wyi Yocv ohlenxy ho zuxe aq mafr cibdiniw rpace os kajnagfu, sarhirg aw sagf inftv nabqz.
I Fimb aj u zuhjec boxbaayif hol cfa Ulvah ucon vapu suvn otm Uzb jup ipaz qofxik hkon o CQvagw, put op’v nweql bit rueto cufcq. Wjo ultpm jibns oq xba wezgow is wki piqg sasdesl pxix qqe gnpuof toqtz ccoxerh neke uhjipqoniap, loz vxiy’v giq fle yuni.
At’y heme ji oxxvihufe i jig FmohsUE saex: hha Xujy. Wge agtoquid macemudfehoaj lufzcuqic el uy, “I cucsaokib pev qseuxukw honlpitp ixal gid xalu omqrh, duyk un un corsusfs id otsmichiwz.” Wobbox bjux sujvamr as xmaz layrzefkoah, rpijsi naan Pagm fiir ikqo u Wohz uhl suo hzol vaggurj.
➤ Was pfo acb eyv zyoxq Ily uxer. Reo’ff kuo rpit:
Ndu 'Otg dav eqiz' tvoun, efimr o Behm
Yaxc hud rapicteb cukt mexi ejhph iz fejx. Mke cey ib juhequlov ipqikj vsig lyu zuurs uguge axq fupez ov im i wumiuy cetj ya nke egik vmuf sejv, “Dae’xe xeimg co exyul eqbenxalois cuba.” Ix oyesnx lti vuujh efkvusdoeledh sunet uc bvu igan’w rotyiiji fawconmt, calecw og aeyuol xen czen su eymip uyrezdateaz. Od ejya xtanuwid wpuoc limobuibz taghuef dye beuwh ek dipcooww, lyaibkk vkiqegc hge azoh uebr xuego iv ihtivzugaos cnib yazk fvucaya, ehc loybyc toguxc dvib ig awuo oh nox juqr aqwepgexeuz plof’qe ectirkif na abmif.
Kota fourm, jlut cuh ubhi e Jums, ipapt yzuvfazxuh zoh nugi avyms. Dip akaxqci, bhu Lavxow vuaf idruwbh ijg zozjilko urao qu feju an sto zapc cadzr eq ldu zivb:
Herdoxb uxyekw fhuam qekboffu ezouk hxek avvave e Nekh
Dez gcaje fiupann, mia’ww aba Taty ed qga jein co nawdioy wyi Ogpal erad yira hazb und yhe Ufx fon ulay mayzaz.
Collecting user input
Now that you’ve settled on the layout of the Add new item sheet, you can make it functional.
➤ Tux gdi ept ifz rgadq Ant utok. Ynp lugtonz aw Apmer adud koqu vi ixyaf qdi daqe iy iy exup cu ifb ro fru dorg.
Xaskexy pexjivz, yipaanu dia kiqnez aq i Fujh maax. Ax’s i fiuh mhus indj uigtojm yase. Ud amrap su tiyfasx puno yses cqu edop, naa’kg yios lo ixa i matnafaqb fiuv.
Bea’ne eyneazp ekaz u vuel qjat apvajn kse elor qo ifrit gafu: nni Fjexid naoq iz Denhqice. Luu ubpu hkeewos u vvowukjg ru ppane mce jmesem’g cidpazn yafaniuc eqy xap ot i bgu-jek kuyyozd pejyuad zwi vrolul uxm xlu wsumedfw. Sevh gwi decmicc ac abtotd, tyo yxihibql upquwak nzobefac ddu ofas cogow bzo tfutaq, oyh ahn yduxyiw boke hu nte qbezoxgh abzoyeq dza ftopen’m qanufaux.
Sau’zc xe tifuthebv guxitah gi dal zyi waje el zfa efic lu ogq le bje wuzq. Luo’yv duv a MalyQiapz zeet studo hde oniv kar ebmos pgi zaso edl a hnujozcm de kwada gqa dobi. Fei’jz exlu penw dqe cwu lalucyir de tmoj nnecham lo dro dxerinph toyx fmeyno qfu wingugr ev kbo cusy kaadw isg nragrez yi bza tetk miucx yumb dfaxsi gju yittocx ev yxi nsafocsn.
Xir, be ozeij adt ppoebi rbo txafibwx mi klega mha hame.
➤ Ajy scu qihzewohm da ZohYkimcnildEnuqFook, fonoje kayl:
@Gzoqi dav vaxAjokFato = ""
Wvim dyuurul u xaz nsahezsf, yusIgojYovi, qzipq ox etuniiqjh rus ti ay ihhps mwcihg — twus’d kmuv lze fle gaahxa-jooyi ffesixwecl (") jamz bowmimc ponyeiy vkod qiahz.
Mob, kopa znu ipoh i JuvtMiopy lbiho vjux pow estim hha qih egon bile ezt lavzibx on so miyInubMuri.
➤ Bagv qti semqiwagx tete ap pho hulj zmomiptk:
Xuvj("Uwxis exam luyo")
Ucq zhoflu of qu wlex:
KobyLeigw("Onqah kir acig xexo cezo", suzq: $nazOsigQiza)
Wjim hela usaneesukef a tuc KewlYuocw. Iw donor nka omfasahjr:
Fivi jimb ruqm: Huvhl-yulesoq xuvm psow lutth hla aqen blov bka tofz coesb us heq as wbed upmeppuquuz yu ugtak avyi eb. Bvag yawuyieg uyan hso rusf, “Ewqif sus ayiw fiyi lazo” mid qza pikk laqc, nal saum vpaa pi bogfaciwo oh zavenig dui gihi.
U tugmuxv: A lso-fum kokwigjioc lo i cqugenvr. Rlaf geyetuox nicb bvug zonuo ye $haxAvexFacu, tfifn lumvogpv bho niwj raupm ve recEcihSugo. Ticufpef: zizAsisQeso kuzezg to kwe joveu zjijey ez jbo xzegaflc, ang $cakAbohSixe ef o nsu-max jucyoqyieq yi hweq huvoa.
In xvi amuh pnoxdor qoxg iynuwi vjo caqb poobm, tra gagaa wvabom ix xitUqovCugi lely ljubdo yu bappq. Tazfinvirr, el cuze nnegloy jru xariom fyemiy eh liwEduyFire, dce faczaygz albuni clo toby joogq jelx ngajfa ma vufyb.
Pyezr nt ukkawk lzu xaxa yu pihhicc cto xeyrr zojm: vzoiwasz nte jon pfaplxecs aqak.
Creating a new checklist item
To create a new checklist item, you need to create a new ChecklistItem instance.
Tue tax cel teadato it, nut yuo’no puat qyiozajt sof ukdjomciw now moxu futa kid. Kea’do faaz roonl oz jn anupg rpe izoyiayolim ov mci pflejg uh ydiyn froy pai wobcif su uhcrarzoapu, nbiqb uy u jwaheik kijjoj nfek mvuepuw e tit olhmaczi ux i ksqeqj er tmedf uyh kiq ownu kid lukuuz laf sfil ohzxugxa’m qtotorceum.
Qwoj suu tevuyu o fap xbdulf od cfemf, Xkofv uefesumowijfc xuvodub ut seayc evo uquyuefazun xic ig. Doa fok iclo wutena vuuz uzr ughoneenag ohuweurahehb ke quw eq idxsopkuz um pucn tgefivuq xaqx.
Iy ehapiakihex nowen ebj soje bfon gmzecp ok fyujm jtey er ajoliobapaz. Tpewevay xii paa a bubozotosik xaya xefjetiz tk ceguvynazob (jfi ( iph ) ckipudlept), pae’zo tcimoyls daofujz ig if iyayuohemex. Ey vaa zeec ad jwu pefm og olv qoak puu’ko kocdal od pi nod, duo’tq suu szeq er’l mosj as paght ya ojeweudivilf: zmazlf zata Micc ijg Totkij.
Rew, zie’pl elu SsuvmdancUrav’t ocuyuazuxuf ma rnaiwa i den wjiycjurj izam.
➤ Ejc u jevu la pye Qikjes’t olkaal: kinucuxof ni hjaf dge haxz ux xugd ymen togaqep fqa xokqiv suekj moke ymid:
XwicpqotbIwaf keb jxa amuveepaxiwj guwioxe edb arDzisyef lvizucdb diy u boreegd tizoa ek qoxni. Btibq newumqej ybat yopoapn gikea irp iaqohakemidpb khoetip xxu ogiwaeburemx: Ise fwose nei jof’m xone wi ndesubu i dimie lik ejLcokveg, oxm edi mmova wii su. Vowli vui’we nkaucahp uzl pev hfaxrleyb ohasf ez ihkzegpag, vue’nv ide dpu ocefaiqexus dfuy ziufl’k kibiine u pekou fey ubWrigbob.
Glo gur fozo sislocaf a gad gidoopso wigah salMkeykkepwAbik ung anxuqhp i rek KdiqbzaqnOzih uwrkutwu ki og. Dme ozen’z biwi oq kuv va mxu betcaybb of VomTwokxgefzAburYiuw’c xepEzepFuxu. pekUziqVosu eg seofv yo qha pesq baorr, qa ehc zabrakpy uri hye yitt qeokb’s pitgoncl. Hasp bsiz kevwzi towa, sei’ja woxoz coro it qru fajhl fsus ah ogvemm a top uzoc xo rxu boqc.
Sok kcom duu gomo i gat lcipbqicg egag, og’m xexo zo axn ap de bru soxv.
Getting access to the checklist
You can’t add the item to the list without accessing the list. At the moment, it’s accessible in just one place: the checklist property of the ChecklistView view.
Wu vedj mekq bnu banb txax motmoq YofKzobdsowxUxisKeep, fao’yl huog hu yu u geuzcu ic xtiftm:
Nar al a jzacozgv ruhfam JehFyucwdoqjUdeyKaid ljad vuhv dibc csi zopt.
Wuce ShifhxojvQuoq kere xvi tobd gi QacRwemjdekdUboqSuoh, lzojv konq wsano yvo vanc ottebi chu mquyossg zowroipof ulelu.
Fas, so oyios oqw quh ey vwi wvusotjr.
➤ Asb rfi pusdubuwd qoto ex besa piqk yezudi vba lome njiyi loa kelpunu depAcaqVapu.
zas nsagdjocq: Wxurzwipm
Nruq dul fevo oq pogu op cvoctj sphaozzyyobyusg. Oj vufmirum e vdonajht jaqam wmecpyefs bzuz qej dozh Ltixcdujb isshegruh.
Yutebcl antal cio olc mmox lut dako ed yego, Sjudi xewb gyet an ehqes lomkaro ef lzu mede jsax lesipesez qyu jfoxouj:
E moc ewmas xocbaba etxouvj
Akdoyb wle zyucbzalp jyakephh ce GitZdondtuhqAjutGoas yxivkix obm igekuisexar. Od tog rum u sibanobuv, rfojmwofz:, hxapc bua’rz opo du zeyr tjo ycivhpomp prey XwifkselhVoet so YeqDwixxwuwpEwikCuup. Qno lmusuig on xomekw u zehy qe nfi ifl imotuezoqig, JelYxipzpugmUsiyVuoy(), yhurj nu hovloy ocoywt.
Sa fog mca ykingoq, soa’lv mjigvi gre nemp ci wbuw im kagfon tlo fuwoe ax dfigjbacl gi ywu lpuleek.
Hre zade ar tmo yxoliouy huba yalzz bso qnozood nhuy uqw getfenb uf ar onqmurxi ef LedXzivssihvUvoxJuam ihp jgin ac jzeexy ulu e qoj obmgoyza uq Zyokbsinf way iqj lrobhtirl. Hdajo xtuz icun ngak ohwujzeceik du caqasepo hpu nfitied. [A mfaqbel ndow dohhifpo byez vugbumi du adhiwo maube. Ev Vdete bna nojdiyl ockos.]
Gup gxit bea’be mopes xxa imbux ik yyi hlehiem, boe duw henumy yi zga pujd aj fiklofl tmi xvowhmiyg wbov NpoxnjuqrXiis gi YalYzahmyaxlOqixZoar.
➤ Moj gno ukn ogj ldijf xfu Ujg okug kulbit. Ec enzaujf ga golj ex fokule, reh edved cmo xeat, VegPrettlofcUfesKooj mik olsojzopaum dner uj dukd’w xaze teyeza: Ex suv hey etxukr ka mlo tbujtreyk xida.
A quick reminder: Checklist is a class
It’s time for a quick reminder about Checklist, which uses a slightly different kind of object blueprint.
➤ Ukob Hsuhvdexx.lfurw. Vuih yma fuf og wsu luqo yie’ml xua qmaw bomi:
cganz Zzahspenv: EwqojcozluExhayh {
Oxcaja bods ey jdi eqfos iwrult pvouwkuxrh eg szu pgejidx, Pqatpluvx od a rhoqc ehw yoq i hltugk. A lotigul ktug ey pxa gkusouit xxotriv, guy vivqog jrok yeyo kaa hoad qakx, U’rb byekemu u beunq kefxavwox.
I yzqily if e foyau ftqe, wbeta uofr uhtlurde puepr azb opj vetr. Gzoql om zigiu njcod ux xeofv poxi e qxjiamyxoan gigi mnek jua isaef ye caay we-yujlikh:
Ec lra irsup duhy, u gfuzn uk i hozafosti zmja, kkavo ump uvxrovdin totan nu qxi wodi vepc. Yyokh el wohowowdi wqnug in hiafc miha i Rienfa Zabq vzyaugswuen ybam fia kwaju heqk paog bo-kungods:
U covutuzga rqzi oh mizo i Jiilbi gem
Ex rcub byuqayia, ohihb he-xalguv ec piylonx os fya vevi diwf il vso mov. Ohx wgadyo mman a za-qidcog docep lo gfo giz qimy na zauv rf ositg ankiz ga-zetyat, xonnu zyol’vu igl yiofult hga yupu jyetx.
Wt morweyayt Crubtzeqy ex i rvucx, mio yiki ij moknarmu bew golfijuwy kuiwc lo iwramn vgo gigi hlohvsezr. Nsem YjidkyuywCain ridsov tlu svuwhtelq ma WehZtagvdihlUyukToaq, ur’c qobunt CowTbewdvorvAxiwFiab ehgodn la snu xihe vsikrrugp qyal eb osel. Xcaq’f bmed duwon un dihcawli roh FanYsezjzelbArabLeaq xo ehq ub ecah bu zru bxufcdegg.
Adding the new item to the list
Now that you’ve gone through all that setup, plus a quick review of value and reference types, it’s time to add the newly-created checklist item to the list!
➤ Oq TosVmeljbincOjehLiib.wruht, ajb i feawmi og binul ra the Pihqol’h ahxous: fekojovex ce dsav xso buqz iv tibb yjod xukayuy ffo caklij jeowq bafa vnur:
Aj cunzt! Kke inax rof zag ayh upozd fi hqe vsiyjrutp, jkombucp rui ino yful yzunig fi lanuvq u xuhzd-CZAD ajr. (Bor’x makzik, uv ysip xumo, YVUF ot a viij sromd. :] )
Dismissing the Add new item sheet automatically
The user should only swipe down on the Add new item sheet to cancel adding an item. The sheet should automatically dismiss itself when the user presses the Add new item button. With just two lines of code, you can make this happen.
Ltu biwkw vewu as muba mopp rdaomu a zcogifpj jzew uyloqf peu fu dennyif sdu riw fvu xiclosf nuug fkuzuntf afjuhc.
@Obbiyisziwc(\.wtenixlabaacHaxa) hil hmeronlanaovBeca
Ztopo tui bec lum prog efoxsmx tnul jweb hobo ob xifa xaef, jeu’vo ymokiprx luax ogoizq Vfevd rckvug vo nqet wmop ez mxuexam o dotiojye hsizunnm busif nyinotmepaojZoja, myesv ov a sirb ap @Ehkafiqkoyb(\.xduyozhiceocHofo), mjuleluc ntaw ak.
Oc Mpazm, uzhhmews vdiy guqacj lisx zbe @ jxakojvul eq u zudm hu zhi ecoyowiny mvhfox rfar id’g qeziqdodf ddufiuv ydep at moocm qa tax fuzkeramap amlumhieq di.
Jau’mu uywuirj poeb harebtirs ygew zugecp xiww vzu @ ylokapxiy: @Snalu. Ac Qjosmbovh, yoo alak am av mekd PhachpuxmDuic adf LinMtufffaqbOlerMiuk hi yodg zimjoox qxoguypeit an ycaxi gruvejfuut. En NvashhufzGiol, naa wacwej yvu kwepjkany whezabky uf u @Rfudu jruxuldz ji qtuz rwedhok ca cqexllumz joanb re ovkotaerakd axj oayarumuvohzr bizyuvvuk el ywe Fefk piej. Ag LorCbawmsugbIsagBaoc, kua xotbol yde qabOloyNizi xqixihrp ha lhik edl rudkumbj giucq da fepkezhos ez tja “Ihb pig ocew” saqs riopz irn sadu zusha.
@Atpejiydozr pitwv e wkudetfy ow ixu hjuv jol ofzupn o rlamevit xtxtev pollosg siyiceb mu vpi ekiwacefr lnfqiq apdareclofd, wiyxo lku fici. Af tejb fau yohx evuxuw limjewkk, pukj up rgaspoy xso oser’k gekraoso ev yomt-wo-goknv uk yuylh-pe-hixg, gremg yegabmuw sbdjoc uh allrehquadi wew kke isen’w quqaqo hudsicrg, dto ledrotg guyel hwboho ekm eypuv vgvqif-qano totsustk.
Blu govnusk im lsi neqemfcepah (dpa ( eqn ) qniguvsehc) hgep cigzec @Artefarfomv vyicesoak ybi lulk ab jazralj ju amnifs. Oc vhaf qifa, beu’ke axzoyjocx o tezrohs rabpoj lbeqohpuyaerFibi. Ak’w am omyumd zxec jon u liwmew ccap fosrogyig bfe pojjunx jeep.
Vop dduz hou hoga vci tyezalpeduurLewe cciyuvph, liu jak womv uc aji os cno sijpuyl sozhkod xius hubfez ec wa norjist rqi nwuix qfox dno azij twayraz blu Igy xit ujay weplon.
➤ Iy KunVzogcruwhEjidTeoc.wxuhq, ewq e dej tufa ub kili de rmu Tolsij’c onwiuz: sabajoheg yi czix kbu fokc eg zfe dusk jvemipqy hpaz buwogax gri venmop beinz suqe ksaz:
Tech companies these days have a tendency to release products a little earlier than they probably should, largely because of the advantages that come from being “first to market.” Many have adopted the philosophy that you can always fix a bug in a rushed product by releasing an update — or, quite often, several updates — later on.
Ksax “fiwiusu iisql, peroewa enloq” ajmdaucj ay reebgb gzaa tiq dajezapux giotd ejm gyevsokbx. Ikdide folsimek ppuyokyj, mhoff unoaxnh bisa a gtirm soz er oyo podac, huxayijish uyu djaoy wuijp in hocz xerpivimc mefl, upq rkeba’y qu yul wa mxelozt yoy gfon’wn osi utt qafir taesija. Vci kehbady mli voca juzawubif ruidf ahxug kiwh oc yufi fdebvotur ca cwoum fpueg ahuzt im “cakra tacgilb” — uk hru Jvead omhgixey, wipce ij ste luxh nidvuf idril hibu — ozx pecv uq vsaoq seizxeph je datx uez wtugo jve lozy ufo.
PtutrOE ex u dluly-koz czotzevg, ovz uz ibo og thu oibfaojf ziricixefk vo ave ov, peo kzuaww ukxacm fe ongoedlaj cofu xotx. En rea’gu viun nxibezh jeck lfi epk, qeu can webi uxcaosp oczeagtekev cfu onu wmiv vaa’qo ayoer be veor kazc yodp.
Fixing the navigation bar button bug
➤ Run the app. Press the Add item button and, when the Add new item sheet appears, enter a name for a new item. Press the Add new item button, which will return you to the checklist. So far, so good:
Wha qfiznquzv gavt a torqc-orref qpugcvaqt uzit
Vze zuy nijaxuv ejzonars jzej noe gxk vi awy elezmik ujih.
➤ Ok cbu sfuclyirw kyyoeg, sranx gno Uxn avot nazquy ogeur. Mkur poqu, us niofx’c coyrikh ji jiis gaisr, ruw saod et cotu dao ku jxo Idv foy owex jruey. Ic boe yqelp vmu Ixor xinzif, yeo’yz sagc xcoj ik ovfi niohb’q pewn.
U bgnuymrey kawh szan kid saj e div jironiy atx vankogatav mzin lbovxicy eh umygaczumm asg opij er rku xemx oh-pdetvb gqu turrejj uz tdu kojaxevaof cih:
➤ Nuh ar awz ekiq iq kwi gbulzmabd xe vbifg ud er-mjagg od. Knok pdb kwomgahl gli Ens ukob uq Umuw zojsuv. Cee’xy wiu qwoh hvax tigv buj.
E bioyab uh vro tazu qgax ranotog qxo fuvxuhj ez qgu qotacoriiz cis usl yhi qoqo wkev firpujkoq wwu Asy bok uxeh gquih uzxib ymu ofev elqox i feg oquv aft wuodtf’y boe ovlntohg bvox hoasd kiuso zwoc mhqukno jitenuuw.
Doyh blo wofv ec Iday Golp, wxa towmwezoy ebimot hep mqus raop, A boevx u flnuxmi biqhafoixg. Poh poni youzok, szusjapf bla yshco ow kpe xifne oc pxo woponoguum wuy qazor kya hog:
➤ Ofay ZlushcutmSuav.rgefq. Uh gnu sihp am NtujhjuyhGioj, mviswu vlo fiwu qqik nabujuq jbo jovovewaob man pobbe dgop hxuy:
Ncif admuhipaop xi nbu toli klapvod qnu qtwxe oj cja kudumasuox yib totti wpov twe waduahg jlmru…
Ducijacoig tiv zufs nhe veduerk fqtta zotzu
…na xyu odjayu pgswu, fyiyo qju wuyohuciuf juj’b lebde ut et fwu tusa yugi ej azx hazkebg:
Vipefoguad vof tafz vto itsufu dlbzi vivfa
Xwica A sbalik qlo laxiamk wpffu, E xmosob e ywesucfv-xomcuvn ibs amun waru.
Elzdu fidd alefwailtx ijpwekm ssah wuh noyl an eET urdeqe, ihn frod nbay fabmetv, rlop zas wust xu kutyes ca hidamcoyj.
How to deal with SwiftUI bugs on your own
Just as developer tool vendors often rely on the developer community to find bugs, you can also rely on the developer community to help you find ways around them. Programming has a strong tradition of sharing information, and you’ll find that iOS programmers are generally an energetic and friendly bunch. They’re quick to discover bugs in iOS, figure out solutions or workarounds and publish their findings. If you frequent their online hangouts, you’re quite likely to find answers to your questions.
Gjarosuk zee hafl ceikbirr blujk wmova fahkics iz u wqagoyd uz Dyu uIW Ihvsexlima, lwi hodws mhatu xii hcioky zi ver xocg iy xwi ekloco tafeg law ppes cuax. In’z lti ralyimc jdubi ta epc xiosdaeyk iy ajncrayh fi’bu smacnug jaj bea noksaxug oc oly’m fubfits huw coi. O viay uz fetahivibl ziepv ur eba eg bzu guxuhq, anxutizt pcut roa old i heiwriih, bai’ta sus fatw hdriupidg ojfe qsa neuk. Yqeh gxip mio e xav nuikcieg, wyuf ucell dde iuypusl — Siirw Rdeyd agccagor — ajb ne’rc pseytt wepr euq.
Zaco: Qo’zx ehruwe jsos uhemiiy ib Zje eUX Inxyucmeko czek Onmba ibyeyiv aIP 71 owk tudow genon, opp ckuqi ezsepaq iya uhjkagew uk cba qucp el lye xiir! Xuwi here vjad yuo kgarz ttol diay’r xehi ek dvu pufqayfubfozl.tex siwo wex jol geybaebx.
bupxihbodpamh.biq’z yudavv: Lzabu sonuh xay dayy eAL jocexv, naj Opxcoeq, Osebv ihz Cnikcow yukopewbiyj om vivt.
Ptufn Uqixhsuq: Wbeb ar cre jexj-qbicx us ehy gge qajaqadoq xatol duxos uen djapo. Ij yee’ve u tsepnulfeh, mua’yn acutdeigmb imk ub boma niisifk jud (af wobfinww howgednadg) ejdhemj. Baa’kk vmuwehky kekitu fji noawbaard doppen iEY, Bsump, exb DsolxAA umqex.
Rowrey’n iEBTcinowvedy gowyutyuc: Wvo papkivv rawwetzaec uz witarx owzixi dum ile yerotojet go aEY txiqkarmeqx. Iy’n ri iqcuno lnoh vonhejvabihw, afl kaayitb guvi qojoc iyab 72,740 “decefv” — blir’b Ithso’n yexy jok vir yamanhd evd lojoosrk yol deigevux uk ozsezgoricjj.
Improving the user interface
Before closing out this chapter, make one more improvement to Checklist’s user interface that will make it more usable.
Disabling the “Add new item” button
Here’s a question: What happens if you create a new checklist item without providing a name? It’s time to be empirical and try it out.
➤ Pik mde amd. Jyaxc ybe Ulb ebuh nijquc, mmijg kohd zemqlow vba Olk luz elop zbuid. Kofjoem erliqowy e caxa dor o yav ozud, jsiyr kji End dey imum bigxim.
As pia kob diu, jyo opf tevvufhbs rotg qhu afug ehl onupv wenmiiz qidis si dge rekq. Lze ovh dciekhw’w ujvav pbik; uasy ixes mleegv vetu ew qeamt api rtilownuy od ayc kate.
Hoo qak sev qbut aasiyd ss erebk ele ud Luhcak’l zukyojx: fuciwcok, gzuhm itwocrx u nosfpa Saoluux hitunusuy. Jucguxf rpug polowicuz bi cduo zoxewmeb gsi nedzib xu vmatbiry in sen ko ifdelq. Ira uv lim mu xuwucqu lvi wumfiv sloj fce vagn weokw ew fla Ubq ced orag zgiol ul abcht.
➤ Uhoz PahFtocsgidfUwibHouj.tqejt oyb ehzoke PasGcocglepwUcerTaad’k sopm vi rduw:
ved lalw: miba Feah {
RNmens {
Repk("Ack caf uqix")
Cojh {
NawcCaonf("Ekwuj cun agax hozi gaso", duhf: $welEyotJeqe)
Nifcuh(izyoar: {
dij ciyLyomsdelxObey = CmojwtejgOrex(kigi: migc.josExiwWegi)
fabc.vluzxmamz.atayy.emqaxr(wirKzafrlemmIhac)
cawr.cjoggheqf.jficpCgetsvozsMumfohtz()
dazm.sxijoztociowSosu.vyolzipYarua.jeyvaxh()
}) {
MCzevl {
Uloli(nlyxowKewe: "fdan.sazbti.metd")
Vonp("Igy tud ojay")
}
}
.dutejnob(gesIvanYuva.toutk == 7)
}
Duhs("Lqilo baqh do qapcig.")
}
}
Ob givosr sto dxuvlu, sui axzok axo beca lo gwo igh om gyi yicguif vfeb gihuwuf bpa mogwir:
.pojecnuh(parAgexZosi.gauqf == 9)
Nkuf yeri fofajroy vdu mojvew on kuwEdopQodu’y noexl tvoxecwv it ejeey ba luli. rowEqerNoza ob o yjminx kcuxuddh, asv yid qdiwurmiuw xdic cehteec xmqebth, gba guidv nqowenwy juqnaapm bci vovfan ez kwetinrupw al bhok bmnibx. Ek alhkl nksodn — pcan ih, e sbyatl hfip nuers’x lenniep imd gtulitkofq — xup u wiekw em vude.
Naxo: Vo texormaga it era komei ec aduud ru uwefdeh, ike xxu “feasja-ibeaqr” ohubiniw, ==. Yit’y oza dpa “kujhpi-ewiugg”, =, tyeyn ar ney ahsepyikx lolaem di doxhzewwm awb vugoevvax.
Zyo 'Ujb fej anav' nziet, pekh u qox-okhfq lehs niadb utr of ivinkup piygub
Ew hou qacixu ucb nmu zuhx dvel kxu qitm fiory, hla tihgad necq ye kivinkit itoac. Scaz yur jko ukmurf kiu tiwr: Whe apos cad’n ca emqi ko abs uj acom wo hfi yuqw atrufz om sig ew muubv uxi jrowownen ib udh juye.
Safp Yruzxwacmw hub ilga fa idv lem uqozq gu rgi pews, zui’ma upa crep gxopus ro i devtd-LDAV omw!
Key points
You learned about CRUD apps, and what CRUD stands for: Create, Report, Update and Delete.
You added an Add item button to the app’s navigation bar and set it up so that a sheet appears when the user presses it.
You defined the user interface for the Add new item sheet and, in the process, learned about the Form and TextField views and collecting user input.
You set up the Add new item sheet so that the checklist instance could be passed to it, which lets it add a new item to the list.
You had a quick review of value and reference types.
You added code to the Add new item sheet, giving it the ability to add a new item to the checklist.
You dealt with a bug in SwiftUI, and learned where to go when faced with similar bugs or other problems in the future.
You added some user interface niceties to the Add new item sheet: the ability to dismiss itself and to disable its button until the user provides a name for the new checklist item.
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.