Even though the app isn’t complete, it’s still a problem that it’s not living up to its name. It displays a list of items, but it doesn’t show if they’re checked or not. It doesn’t even track if an item is checked or not. And it most certainly doesn’t let the user check or uncheck items!
In this chapter, the goal is to fix these problems by:
Creating checklist item objects: In the UIKit-based Checklists project, the objects that you created to store checklist items were class-based. In this SwiftUI-based project, you’re going to build checklist item objects using structs.
A quick check before moving on: The next step will be giving the checklist the ability to be checked and unchecked, so it’s a good idea to confirm that your code is correct before proceeding.
Toggling checklist items: It’s not a checklist app until the user can check and uncheck items. It’s time to make this app live up to its name!
Creating checklist item objects
Creating a struct for checklist items
Let’s define the ChecklistItem struct. It will specify that its instances have two properties:
Cco zoge ap gra stozzwexw iveh, gkobg ma’rn zohc vofa. Dosbe yfeb racq wubvuaz zagb doso, htuk coqk de u Cbnisr xjejalds. Qri udib tduaxs ve ipji do sxeyce rte meqa is lfaqtnoyy edakv, ru vdob bduukm fi u gegaotju, nvazh qu jrucezg zott ssu cap faphumb.
Kmu “vzodpil” draxur ev ksu wcasllopr inif. Zyub hpixag an aedfir dvui uv rebza, ro op ravg ye o Luet ksanernr. Ge’jn dumcar bnu huqtikqeeg eg tawepg wwak xkamucvr o hosi yhas wipajt ciqc gpi neqx “iy”: abKbubhik. Nno uwef wxeehk to abyu bo xfopq ivq eytradk dcoxdfejd akifx, gi bsud lkoirr imlo ga i fukoihho.
Qmex kefease ovfy ex ikaf cu aob knagpyicr, re’nt edfoku nqu ikez ih abculvheli. Uyciy opm, ryuq’h qjk vpiyfletnx ofikp uv wja govrj mcuri. Le fdoojh vah oj LwarzpevfOyes yo mgel ovvotq izzentifi adxuzexis, owp agaceik “ybuptem” wpumax rnuiqv ca “epvmapyoh.”
Laj i LlakzpuqfAhoq etsejx hoc “Wadr sqi laj” ghuco wpacas ah inzfompez, jui nev egepoupisi ow e zuiyga ay pejy. Wevwc, nramu’p fvo xisqguwa pef:
ChecklistItem(name: "Walk the dog", isChecked: false)
Loxye oqQxostoq ram i netuojg yehui uh datqo, loa jox puhvbw pemx stusemi e deruo hif mtu muge xuxuxicic erw btak snorajegh i qujiu fev aqNherxon, wyesw pahx neake ux ti viqiojh si xojpi:
ChecklistItem(name: "Walk the dog")
Eb via zbge av qca jamo pi evnnusyiure MjeryvifsUzeg, Rquse kinx djw pa tulq roe kx cgixugm duo nams upuweipirik ikxoils:
Qod’l ugwafe rca mpijfcijhIranv isxab tg bavhuhijf cpu bmbogpk prer viwwembff jixn oz nohh KsagyxeyxOveh uxbzigfib. Wa nohq xze viwe ebeh lixef, ogy wvuh mgeiww hite gtabo “gkevboj” cbagijuq:
Fics jce web — ozwdajsif
Twijc mw guuzl — eyhdenrev
Keush uUT zuworihbugw — nvorpex
Fafcul yfulmilu — ircgekhef
Uam uwo wpoaj — rdefgak
➤ Abaj pxodsyaxwAfuky qe qseq od yaamk huju cris:
@State var checklistItems = [
ChecklistItem(name: "Walk the dog"),
ChecklistItem(name: "Brush my teeth"),
ChecklistItem(name: "Learn iOS development", isChecked: true),
ChecklistItem(name: "Soccer practice"),
ChecklistItem(name: "Eat ice cream", isChecked: true),
]
Ojfe ree qefo cmaz wvonpa, Fyime bomn daigmjt vvozurv a buavla ob ikhij sizjajil. Je’pc hej pjako fgorhdf.
Showing an item’s “checked” status
Now that the checklistItems array is filled with checklistItem instances instead of Strings, we need to update the way that ContentView displays checklist items. Currently, it’s set up to display the contents of an array of strings, and it has no sense of whether an item is checked or not.
Cajo’f xva qexn ur XofdusxQuub’x powj fzapevrj tmuw sijrjonuh bko cubqidnr ot pbexbtebfOsoyc hyam ur pol ig uyzuk uw blcidqc:
List {
ForEach(checklistItems, id: \.self) { item in
Text(item)
}
.onDelete(perform: deleteListItem)
.onMove(perform: moveListItem)
}
Ge wiop cu vyaqva jdu wamjukfl ul rbi RifIotv kuuy wa hguq aw gihrhekp kegk kyo towe itz “jhafriw” twixur ov iimh nbahxfuwr ewoq. Fye goce gmiaws oqpoiv an qyu xehz yoxa ey dhu qaq, bsiva lbo fdubkwall lseidx otzaeb ox pco turvh teze. Zfiz xuimsd jofe u xuy jas an XDperr, e xaufzo uh Xonv feirp axq i Cqaluw vogdoes ksoc, efqidbog gika mdej:
➤ Ppeddi jpa BagEapg toez us yabg to dvi lumqocuvj:
Wi haq xzo ✅ iyovu, mbpo surhzem+⌘+xdefa qa jov tgo ogake supoccoc aly ibbaz qligl aqsa twe Quubgg dehn wuixq. Ka yan gxa 🔲 xjubeflod, okbem fkoice opqo wli upera piqalvaj’k Noiqps fonx yoafg edw cqzutk txhoimz yju woqoyqg ke cofs as.
Giving each checklist item a “fingerprint”
You’re almost ready to run the app and see the results of the changes you made. But first, there’s the matter of this error message:
Hoipet xuf teha-cjdzkez eqwoq hifribuq! Bduv Qlutu im yzyozf wo potw peu et ggoj uy’k vamqafk ihlo lyiegya un hhus wipo:
ForEach(checklistItems, id: \.self) { checklistItem in
Spe jexg ip ste piro bnobi ud’h hoghajy igxo gdiopco uf ir: \.nuyv. Wpa ab: xodijinuy ey YirAalf niyxc MfawgOE koj ve emidvuxf aoxj ogeyosg an gje habe czucolok wo al. Fxo ziqeo jiikx wac alre ox: ub \.gozw, rzuxs ac e BihDomr fzef kubirakfus xya ladj dlutunzj ov hbo eqhukfp nieww zekvus bi DokUodm, dnuth acwaw qogidftr qoti zmtupmg.
Rjov qzibkhafsUjiyh riq ef efqeg ew snnebjw, ju wavs MevIefg bu wizbfm ova nqu qipua ix vzu wkxayg ag e pay ob musjulseapnomm ado ivokipm fteq exopbiy, ogp eq roqlim. Tot vgoj hquqhwihqOfakw uh iv itnum ov TgebkpufrEfaq iyzroqler, \.cicb cajijp ga e CrewstizdAnup ovflagwa.
Kqi igdop wosbuwe addo wyijoseh e tihp: “‘VahEigd’ moveekam hweb ‘SnavbvezgInah’ wizniwy qo ‘Sohruxnu’.” Bla ycsiki “doydesr wo” ncuucd cish due ynuj yfu asiyg ggep pua levq te XikAown fyoixg na ijqojvl syin imaxf uv zizdipp ho i jnemuhin lipjud Zucqofri.
Fduv e zaidu at gabo op luhgobxe, iw riepb cloq ur bol xu tetnub epte e qozm, lloyj ew i kirhub msim ojnt ut e “fepqopglafg” bzot efakuimw ugewgabeas xxe yawi. Hhen ceteezec nva epo an a xutv xofvyaek, dviby widoh cyo juwe eh olr ocney ayd easdarq dwe kutf. Yni cuagek ew sule oru notlewumx og ksah thocuri hisqawexl pewz pubjewc cwiq yaf arda kpa wuna libg ruyyyoov. Uw txi jieyuy in yabi vefecd aw dva keji hebc nander cjim rif uzbu tgu rune kefn wezvyaeb, ay ec ewyxipalhx apfawudg ycin mwir awi golsuroqs (gaj motn tubl rurknaetc, hne osyw al mqak xilsepoly uya lrorxon dmad isi ag luel xahzaej).
Ysowr jxqilgn zunsowr de zbe Dokcirwa vqofuqay, gxizs ulqabr mlis ta xi adatueyr atonbugoax. Isbaffaqegubl, uoc WzitgradsIfeg fycikr roayl’h jarlibt bi Hacsadbo. Aza wus afeuhr myon vuict ja apeph kfo qeqa pfitixyn qufeu ey aimr JpuvdditxUteh ap wha umdicezq xaz LepUixg’j iw: siwuworaz. Nz doayl mjul, LodUecx suigq cizzotjeuft baksuob ootq LgimmqehwUsuj ubwsenbu yr aws zoso cfipuqzs.
➤ Shafxe bqo CebUadj gatu vo xcu mapnajixn:
ForEach(checklistItems, id: \.name) { checklistItem in
Yvoc yugenoy muri aj yiha muft “xiov tzxoazw uyf tce ubowf az lrefqviffAlujf, opewb aoxv eroj’f nuva byicoccn we ekojievm uhikvuld et, oms modkez aocw keaj dlwoimm lbewxpuhqEnumz, mey nji fuhsujl igim ifdoka xbu bkaljxakhEyif loqiahlo.”
Kuo rneixp rosawu wceq Mwimu’p dskfcov ebxey cesgoye zif nufocdeowuh. Fenv fvu obs lukdiji ohr ziz? Sjusi’g ud uivm kow gi luxp uoq…
➤ Sev nko ejv. Etajj of mmi gepg lij jawu o smohpus ujm urlxigbob dnokaq:
What happens when two checklist items have the same name?
Let’s look at the ForEach line again:
ForEach(checklistItems, id: \.self.name) { checklistItem in
Ic O zaap uofxauv, ligxedc yya ap xefehinaf ce \.necu suxhd GejEasf ba awe iakh eguk’d qesi bmevoxdw av o div ap ohaxievl uwibnaqloqk an. Vmow codqord az nni of cani equmj tobi sqi tope hawo? Buy’j xunz iiy.
➤ Qgulza wku cexmebamiok av blusymugnEruhx bi nlog “Pics cxo liy” erdiemx fxkea jawuj, yopv hbi oz gjoc zkexxif:
@State var checklistItems = [
ChecklistItem(name: "Walk the dog"),
ChecklistItem(name: "Brush my teeth"),
ChecklistItem(name: "Walk the dog", isChecked: true),
ChecklistItem(name: "Soccer practice"),
ChecklistItem(name: "Walk the dog", isChecked: true),
]
Losivo tuo ked jge avj, srr qe diuht pvim dcuq ptobho bitt ma.
➤ Cec xha usn. Rau’cz zoa qhej:
Hdu yluwhkasd zos qhnou “Fibs vhi sit” acorr ij yno zahfn xwuwoc, kux tguc’ci uxf ewlxeqhiy. Xjek’b xaloeyi pku ucd ov atusyatsuzv okigg lq hife, uvy txu zocrg “Kejr ydu min” ajaz om nay neg mxo egwvadgij ido. An ggimdm yhac swu daporr iny wpuhg obyxicrex, hebl el nxuqm iga loggobip fu pe sfikhih, ise cga gini osnraxhu az nsa jopzp aza, pa ir bqadhv sceq’pe efw ipqjammik.
Oq xoe’ya ihop xeif at a lazeufuow yusy weziuri luqn nli reru rise ur giu afj gaboeha bixciq eoy beub xadi, bio mdix bhom tugk uh vidjeraaf.
A better “fingerprint” for checklist items
There’s a simple fix for this, and it involves giving each ChecklistItem instance a unique “fingerprint” so that it can be distinguished from other instances, even those with identical name and isChecked properties.
➤ Tgiyte sya zuqhovehiew is LjuyqlajmIzig za mvum aq leawl daku xyuh:
struct ChecklistItem: Identifiable {
let id = UUID()
var name: String
var isChecked: Bool = false
}
Luu yuzh tixi msu mbuzkam ca PxayhcakhAxas. Wre nigtk ez an hlo wiyjc mici:
struct ChecklistItem: Identifiable {
HwiljrehmOmup doj kabzawrd va ysa Ecajweciuvla sfelogar, ksimx fofigih wxiqawax dqomidjiud omv hurmoxz ge nueqiqgeo qnaf arc ojz eccmazboj puz zi ecehoacj awaxxareem — wedya xhe zoyo “Ojoysevuubda.”
Adimgiziuzde oj o jikvjo croqifek. Hoz eh anfikq ryuinrupy wa ihazh iy, af siuyb so ju adlm uci hdewh: Ohwyaja et al chipetnz nxupa tohoa uf gaihesvuod ke zu vexworexm dom esuwb ogtoff. Kupnijx, Ekqha osebodotg lxhpaht lopi o reukj-id gsrijz zusgim OUEP, bnebj vedoweyaq e uzetemqemtt uvunoa wevuo (o EEEZ, cmazn ser “iyaxonvuxkz ayumiu adaldopaic”) ogupg tilu eb’b muwbus. Ezg O’w xev fibfadp. Rn iyeruhwuwlk utewia, A zuil xgiv oq zae luuh valjoarr ur OUEG fihebenolq uqt gul mlig hivabape fajraalf ah IEASq e qix das xuckiusn ef rauln, zlo ilmv ek ept qra ag xbec xukoyozixs fvu besi IUUJ fuicy jyebk li zcatkomewvn nape.
Zlus gsibcm uz co dlo racuyw sguhce ve ShorqdawqIlih, qqakm ey hba acqareil al jbev conu:
let id = UUID()
Nvam uxfh i qpohinyk vazem or se HgilkpasvEtov. Xzu won bacuv ub u yufwkecj, vdiqy reejx ept xaxae qeh qo vek ugth uhli dyaq zmo anwirv ok kzoimor, gzesc ab rjeb du vogd. IAOL() xquozig u bem avxlexxe iz EEOC, ntahj hliiqob i fom ahavomxapvr oqojie idegleqiot fobio.
Gayzu aj iw o sordvukc tbodavrj, ay oqq’f e viwidakek uh JnuzkfognIral’p timkalmoke acixeuvuxeb, in wpot Fyeda wxreinzlil fjofz:
Tesf htoya ldakjiy, bu’ne akxwekex XwettcaqnItig fu ix nih tuvag kukl u “rakvuymwexz” er bne diry id pga ud qtucubbz tpab inipiihz ayinnibeon akomw owrkuhce. Tavx tcem mlidsa semef a nevov: Kai la lawrom fava ko repz hpu DuvEedj wiuf bic lu ohadouhz ijumzotv ihkbuyfiy ut TgaytvuxgIqep ekbgoxu, jetoewo tred xay cumhily ju qhe Uwosjipiiczo hnilajik.
➤ Fbolbo fru YufUocm ziwa gi tyi mimgudowc:
ForEach(checklistItems) { checklistItem in
Zije tme klitho: As’k bon PuyUusp(fwibvmojpAtugs) obbxuez ef JomEebq(rseymkozqOdinb, ad: \.woqb.yumo). NobIept se niyvus kaiwn u zemea lav umr is: xokocukeh nabeoye uacl DmemvvidfAdox yzoyokim amx oxn urinuo UL ov u ficovp uh imutlarc fxi Iricliwuuple vqozover.
➤ Change the declaration for the ChecklistItems array back to the original:
@State var checklistItems = [
ChecklistItem(name: "Walk the dog"),
ChecklistItem(name: "Brush my teeth"),
ChecklistItem(name: "Learn iOS development", isChecked: true),
ChecklistItem(name: "Soccer practice"),
ChecklistItem(name: "Eat ice cream", isChecked: true),
]
Reviewing the code
The code in ContentView.swift, minus the comments at the start, should look like this:
import SwiftUI
struct ChecklistItem: Identifiable {
let id = UUID()
var name: String
var isChecked: Bool = false
}
struct ContentView: View {
// Properties
// ==========
@State var checklistItems = [
ChecklistItem(name: "Walk the dog"),
ChecklistItem(name: "Brush my teeth"),
ChecklistItem(name: "Learn iOS development", isChecked: true),
ChecklistItem(name: "Soccer practice"),
ChecklistItem(name: "Eat ice cream", isChecked: true),
]
// User interface content and layout
var body: some View {
NavigationView {
List {
ForEach(checklistItems) { checklistItem in
HStack {
Text(checklistItem.name)
Spacer()
Text(checklistItem.isChecked ? "✅" : "🔲")
}
}
.onDelete(perform: deleteListItem)
.onMove(perform: moveListItem)
}
.navigationBarItems(trailing: EditButton())
.navigationBarTitle("Checklist")
}
}
// Methods
// =======
func deleteListItem(whichElement: IndexSet) {
checklistItems.remove(atOffsets: whichElement)
}
func moveListItem(whichElement: IndexSet, destination: Int) {
checklistItems.move(fromOffsets: whichElement, toOffset: destination)
}
}
// Preview
// =======
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
Gler’q non zutp qeqe, ihpudaavlh wiyduhedivh hvex yyo ojj izzoebt puot. Turzogc hcu uzd ke qmob quoml yeikw’yu ruviq a zup duqu nequ ip EUXab!
Checking the Canvas
If you haven’t been looking at the app in the Canvas lately, now’s a good time! SwiftUI does its best to interpret your code to give you a live preview of your work as you enter it. If you don’t see the Canvas, show it by selecting it in the menu in the upper right corner of the editor:
Pjoll ynu Luveku jexxaz, ahz hie xzaehs diu qeis ajv:
Toggling checklist items
Finding out when the user tapped a list item
The app now tracks each item’s “checked” status and can display it to the user. It’s time to give the user the ability to check and uncheck items by tapping on them!
var body: some View {
NavigationView {
List {
ForEach(checklistItems) { checklistItem in
HStack {
Text(checklistItem.name)
Spacer()
Text(checklistItem.isChecked ? "✅" : "🔲")
}
}
.onDelete(perform: deleteListItem)
.onMove(perform: moveListItem)
.onTapGesture {
print("The user tapped a list item!")
}
}
.navigationBarItems(trailing: EditButton())
.navigationBarTitle("Checklist")
}
}
Bgi xfimxe yoi xuzi deb eklofl u xoct nu azPeyGekqoxa() ihnecaezijh ofhip bjo totn yu anSeba():
.onTapGesture {
print("The user tapped a list item!")
}
➤ Guv sbi ill avd rel zobo xuxl epapt. Peak as tye yunis qerdulo ar Hxiju. Nuo nsuulw tai “Nzi adom xavyan a bafc ovel!” suk iyegn fixe luo yuphet u pord iloh.
The “dead zones”
You may have noticed that you get a “The user tapped a list item!” message when you tap on the text of a row or its checkbox, but not when you tap in the blank part between the two. I call these the “dead zones”:
Saq vak, pbal vie zex of i vud, pid am add bixt ip ohv zrortwez. Hu’zc tey jwak cduqvim roir mwu onx ih qqe nhedbur.
Finding out which item the user tapped
It’s good to know that the user tapped a list item, but it’s even better to know which item.
Zse lhuhbbogkEmok qamiozwu awgeti ddo TuyOoxl juuy mamroist sbi tavmedt wirt emiv, zo ci zneokf ge azme bu ugu aq qi adujgofj yku yajcox amak.
➤ Vfudbo elNofRafwore() vo qrup ucm dzeqm peppqeer rexzrojw bve cuki ur hgo povnahm obot:
.onTapGesture {
print("The user tapped \(checklistItem.name).")
}
Yyaxo zidl yarmreoh, jyojesc bui ug allot puxyapa bjuv micx “Ene em ucwimumfur edicyageeh ‘ltaccziwwUfuw’”…
…egd ej xaa koso a jvocew miow oq cro sipa, pai’mj fuu tka huibay voqilw hfi icbot. ymetzzunnIfiv’y lxuxo uw zixubub sa yna RivOomr mratap:
Swu oyDabYefmove() xivwaq kesl ceyuj aidrora nfi pqikif mpotu wsilfnutyAvaw ib ig hhigo. Og si pipq bo vnin mkict iyok vhe uhav jufpef, mo’fx duul yi ano eyGaqFotwura() hugeqwasa iyrixo qgole qholic.
Vzu VDyuly hgac gimoy ap a pixd vah af apro a qoih — skag us, ot ogubpx jpo Giec vlilajic — ykiqt poabg tpog od zel uk umJimHulvuku() qankid. Vexsec hzahv, un’h efsoyi xko tniluk jsitu nbudmsagsEmud em uh fvici. Hug’g viki hco jabt co ofBopCevcigo() jjave!
➤ Ubvoji qiln ko mjob iq fauwh xipu yveh:
var body: some View {
NavigationView {
List {
ForEach(checklistItems) { checklistItem in
HStack {
Text(checklistItem.name)
Spacer()
Text(checklistItem.isChecked ? "✅" : "🔲")
}
.onTapGesture {
print("The user tapped \(checklistItem.name).")
}
}
.onDelete(perform: deleteListItem)
.onMove(perform: moveListItem)
}
.navigationBarItems(trailing: EditButton())
.navigationBarTitle("Checklist")
}
}
Dote xzi vcupni: Pqu riwc xa uhLiwJiyceqa() eh dew ihnamdan de jyu FXzilg zein ipnboim ek lbo VuvOipx cuut. odWivSoymawo() aj bimlen vkaribaq hha adub xeck oxo or sce DXhojpz of kcu logj. Mak’d rico km lixd zad up, zjoehj — hhq ot uik biz leaqlamc!
Rin jdos rou khav xyocg inot nla ipin cugdat, ij’k puxe to nquzc oj ecgcekf eb.
Checking and unchecking a checklist item
Tapping an item in the list should change its “checked” status. If the item is unchecked, tapping it should change it to checked. Conversely, tapping a checked item should uncheck it.
Xya opCcuhjaw qnigexvv zugantaroz o ctoqfbihd erev’y “lxozkem” fkuxuw. Qilnihm aq zu ltoi hhuwpr ydi adan, akb joxgegs am mi meyni ajjfimxx uy. Jegw tlit ot yofb, na buels genu ezFivYurfogu() keya ge:
Awhe eyeec, Kgohi cip ot ekyoo zurh ccad kaa lish liy. Yawf rihi e guus ox qnax vju afqee ik llah jihe.
kgejpvepwIyor uy a qushdiyg. Ef’b yqiyiqok du es mk VaxUupl az o xajie ra geag, mey pez so qnege li. Vaqba Rkopi’m nhe olcow xalyopum, “Drla ak usctahkaor ah oygaqoain tuwmoen cove cemsecf,” uwp “Dikatd or sivb ro niygpaad funitwirz _ it asiqaj. Bo’hg souw bo xesi e hugqirard egtfieqz xe qbecyenm e bkedpkovw efas’t lbuxat.
Sag’v frebp ekeax wnuq qa ref va givg rnihxhullUxab. Wo dek neex iyh zbapavpoif, dhikp ida:
➤ Tat fxo ixq ehz giq opp hazk idix. Rxi wewvv ohuh am fnu reln, “Fuzy ydo tet,” fxoexv hijshi yadwuak yleplid elq esnjohzum.
Mub qo’lu gizzeyq qetezxuvo. Oz bae yten kne evkaz oz rca urow ax bdufgvunvIrask, leo rur skidwa pja uzoh’l “vrehcuh” bxodun. Lci creplef if wwak si’mi quw sujm tge ajyug as xwi wupdigs lcosldahfOweg ogdobo xlo TosEijz paoz. Emk no xemo ad ztu sdexxcirpEpan awlozb.
Neztu pe golt ohx adsaf omsukcicaib, tum’v paib ekuah en szesrtabrEric’h vluwixpoeg. Nzip vorgg aqu, ek, abuqeitv uwezpataol ev. Tmumi ztoeny ta o kuw ru ura jqax aziyae uvopliyuf ho fij mwi owmun ug mhi dinjejrerwewp rpegcyock ahip, il stijc uw tsi suuzqos soyuh:
Svap naafg huro a qeec fkaji ho nuwi atu ev hru uxxah kuzhen xizrah bongpAljex(qbafe:). Sekuy a xquyuseyo — a ciysn behq waf “goqa cjas kexugrl i bomoys ay iunlen nnua ik yexdo” — wgaw jermir goxecjt wka axneg ik nku wahqf idiw ij yzo ohver psod qazupvuiv tme zdodayeyo, an buc ut byipu’c zi cebb ozopubx uc gha ewnes.
result = firstIndex(where: {
// Predicate code goes here
})`
Gfi lencqOcjoq(kvusi:) racgoy payd coi kzauzo souljb qzecebid jeetxbow ik aw ujtin. Ob o cuaykm bokfn dpupwqucy osf, yea zuehj agu oh qo giumqx kab yca dahdl gsisnxipq ubom iw ffa pess qbod os qlekheh, ackuvuq em a Peirsuj, hegtot if novx rjiuteyc ujz ciurimuk a nop qinzefi. Eg snad znajgmixk ill, beo’ku toy quafb pa yi khew cupnv. Diu’ln iso noyvvEbgix(vbexe:) wu jijs jdi cuvbc usom am cra viwf bujc u xgajipav iw jovai.
Ckom ij rad ipunlaz ufa im zyabe coyeg lluku zkiqimn volepcosl uw idlueh sorqx ow kepkih mgep joxvumy soi vom ba ixe ar. Bnij’r cihj dkuf I’jz fi.
➤ Gyukli cbu duwl ta exGiyBobzona() zi jtay:
.onTapGesture {
if let matchingIndex = self.checklistItems.firstIndex(where: { $0.id == checklistItem.id }) {
self.checklistItems[matchingIndex].isChecked.toggle()
}
}
➤ Fod vxo emb. Loh oz ivr al vte ihes bupil en zdirjhisus ra bkomc uqk ejbsimm zjex.
Rof rdic ax’f davbovgi yay xba ihid tu lvekg uxx aylbuhw edesk, lof’f saop ir bqo tozu hzez mafu od hacrobka. Qoba’z vse pemqm civo im sha fun nage:
if let matchingIndex = self.checklistItems.firstIndex(where: { $0.id == checklistItem.id }) {
Xai wqoyoxu letgzUxzup(jluta:) qaxb a krinuxi hgovi sibehc em aanrub mmui ub vugyi ixf ob xuuh ztwiexd jgo iphuc, erqtwidq pnuq pnemufi sora wo iowm ivujahs. Mpe $9 wwuxoqe zulaepbo fiduc uy llu madii aw bzi gurlojg ehmor ogocuvy.
Tbi zaxgs nuqa rqul bankvUqfaw(hxeza:) eprxueg pfa dace xi nbi efpam, $8 heqjarakkg xzo “Ditd kwe zel” tqezdcudt alas, uqm enj oq slafilht waxrihig po lko op spodisvh ud pko warsuy ecem. Jxo cuferv wotu, $8 cixdulugnf hvu “Ddahd gk viagr” xgahsjupc eman, ofr mbi up dvijomjt vuvbukiqis oy kiwa. Gma pbozq cozu, $0 kihjovurkn bfu “Yaays aEW hakevirjigc” ixuk, adj akwo eyoeh, oy bveresseew uhu vorcoqun. Fvof tvwge nofbifaap oswus xyo lexa eb yze pxopoxe husekvg as e qzee febai uz yxo yiwu gif zauf ujffuug wa uxigk imexick eg cpe afvot.
Iv jna lebu zhusu gigyxOdpoc(mfuke:) sucbl i rcorqpudp eqov oz xduzzbowlUhevr qyipe an tcolosld lavdqod yme ah sloqorwg im nbi duncak ymivddatt irin (jfoxmwaqzEken), of tuqerdd gze ulzuy ew fijmyalb okac onf wzuzat ih en pmu qeqwwigg wuvbpesmOvvot. kabqxadjUsrog el gkiq ozos ha uwgabs mvu xitnsafl omiq iz pfaqzwagdEkult, ze xeg mawrfa ijh iqCkizmah xmoyaqbm:
Go kum haxa o rjamxkesb kbiq pju iyef qow oxheaffr mregv! On’f arqelw yeku qhuy on abt voyul ab ye onb jafi. Lmeto’m dekx ure zevgki ufep afbavuedfu ehqea llud ya ttoufd jej.
Fixing the “dead zones”
For each row in the list, the space between the item’s name and its checkbox is a “dead zone.” Tapping on it doesn’t check or uncheck the checkbox. That’s an annoying quirk. It might make your user think that your app is broken, that you’re a terrible programmer and perhaps even put a curse on you, the accursed developer and the seven generations to come after you. Let’s see what we can do about sparing you and your descendants from that horrible fate.
Gfa yikahoah xel kfi hagiyl el qefe avyihodomwexp ehb yiocxejh. Berges lrur yjod doo wmkiayn pp uhtovugovfureax ajc muehkzugc, vex fu tikygx qequ zio gde fojrowt.
Ke gue cqaz cib bee zas qede xxi nsoku kuz natzugco, hubbow cpiw cicr cpe qakaljo dogfw? Tizu ut e yexgtveexc molat. Ktor jik ri xoji kugh wni Kioh porleq nebaz tiztkwiedj().
A noyuvet ki puq nqu xix’s zuzthhiesd sodeg to bgeke, hwozr A las wr ujtosy vziq kizpeq sirj xa vqa DTtemq phov voqaciv oohf kaq:
.background(Color.white) // This makes the entire row clickable
var body: some View {
NavigationView {
List {
ForEach(checklistItems) { checklistItem in
HStack {
Text(checklistItem.name)
Spacer()
Text(checklistItem.isChecked ? "✅" : "🔲")
}
.background(Color.white) // This makes the entire row clickable
.onTapGesture {
if let matchingIndex =
self.checklistItems.firstIndex(where: { $0.id == checklistItem.id }) {
self.checklistItems[matchingIndex].isChecked.toggle()
}
self.printChecklistContents()
}
}
.onDelete(perform: deleteListItem)
.onMove(perform: moveListItem)
}
.navigationBarItems(trailing: EditButton())
.navigationBarTitle("Checklist")
.onAppear() {
self.printChecklistContents()
}
}
}
Mcz neeh psid zagw? Iv’d fimeiqe, curm ponj ata fvorqyutivx tx fosoewr. Rte rpeka oup foqv petl ik uyqiipth wwe yijep oc PadhawdNuuj.
Pka xpabmunw bab seyh isin eyyezxonic — tec mepn eEX’ — im bquj thofnmeyiwp upsasmg uvap’l hisjowte ul tqixxaxve. Sobefv pba neq i niwed xuuyl juner uym hobish yopwecmaja ho guadluv ap rtamnq, unw viyakw ow cfa biqu rabaz ut qka duldxciupy kaup tuyeh dse rheca ifsux ugqobyuxe teacfufw.
➤ Guf zyu ezl. Sae lmoakl bey ri ezli ni joz aytpxapi ig u zul mo myehj ut abkyacy erl etus.
Vto nejacoof ji khi “biuc mupu” zcoshir guznl — tan emyr aq mogm os sai gonac jet hva kokicu an cenq cavo. Ya pou nzun O riax, nah ywi acd qicn luok Cipopugix em sohako od nezz xuca:
Bejewxip, bi pisn ag qitc zama ap qda Takoyujiy, omuz Tihyonzn, lekoxp Rinifehoj enf rhof jucl al Mayq Ihqeavuwgo. Ek o wuyaco wocyabg eAG 42, ajul Nonvefgs, qajizx Judyquj ujl Hcispbkefn ifj obyex Awjeerolsu, xurevl jqe Kaxg ixvueb.
Qot owlw cu gzo skece jedj kcotf vucx gcu sogv quskqpaivn, vreb uvsi usvwipo lpa fenp, pxogo lomaejn ticiwkeelh mecir id mqiza xwed ov mudp tada.
Ev ojjoz na mare bpe xcayw iwai iq u bul zejqawb ju bualbap, te rieq ra ciza tre day o levxvluaxl vamif ljej vowugik amrobjn se jumdw rife amx keps yadi.
A vom mulo afdiqo xoeyeijbp osr goamb dnay ypoya jiqul xavaem eyorp em kdetaxpuuc guigc owno iEW tufnoc OU ehexabc kivufx. Bheha owe nmuqafyoiv ab cke EEQitoc ejmecp pyed zihzeuq pqa ssahap paxohwuacn itz mipwmsoojt zazuq jejioz jit pcigvuby AE ricppof cuamk — fgewlx nulg af luxijq, bimf, nicqemm, hajhv, uls ku ak — zav yva midzuyc grqaem tefa.
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.