In the previous chapter, you added a key feature to Checklist: The ability to add items to the list. You’re no longer stuck with the five default items.
However, you still can’t fully edit an item. You can change its status from checked to unchecked, and vice versa, but you can’t change its name.
In this chapter, we’ll make checklist items fully editable, allowing the user to change both their names and checked status.
Changing how the user changes checklist items
Right now, when the user taps on a checklist item to toggle the item’s checked status. Tapping an unchecked item checks it, and tapping on a checked item unchecks it:
We’re going to give the user the ability to change either the name of a checklist item or its checked status. This will require making changes to how the app works.
Let’s look at the Reminders app that Apple includes on every iOS device as an example.
Here, tapping on an item’s name allows you to edit the name, while tapping on an item’s checkbox toggles its checked status:
Building this kind of user interface, as nice as it is, adds more complexity than an introductory tutorial should have. It would require changing the code in ChecklistView to support both showing the contents of the checklist and editing any given checklist item.
Instead, when the user taps a checklist item, we’ll take them to an edit screen that allows them to edit both its name and checked status:
The edit screen, which you’ll code in this chapter, will contain a Form view similar to the one you included in the Add new item screen. This Form will contain a view that allows the user to change the checklist item’s name and another view that allows the user to change its checked status.
With the changes that you’ll make, you’ll have a fully CRUD app by the end of this chapter. Checklist will be able to create, report, update and delete checklist items.
With that goal in mind, let’s get started!
Giving checklist rows their own view
First, we should look at the way that ChecklistView draws the list of checklist items onscreen. Here’s ChecklistView’s body property:
// User interface content and layout
var body: some View {
NavigationView {
List {
ForEach(checklist.items) { checklistItem in
HStack {
Text(checklistItem.name)
Spacer()
Text(checklistItem.isChecked ? "✅" : "🔲")
}
.background(Color.white) // This makes the entire row clickable
.onTapGesture {
if let matchingIndex =
self.checklist.items.firstIndex(where: { $0.id == checklistItem.id }) {
self.checklist.items[matchingIndex].isChecked.toggle()
}
self.checklist.printChecklistContents()
}
}
.onDelete(perform: checklist.deleteListItem)
.onMove(perform: checklist.moveListItem)
}
.navigationBarItems(
leading: Button(action: { self.newChecklistItemViewIsVisible = true
}) {
HStack {
Image(systemName: "plus.circle.fill")
Text("Add item")
}
},
trailing: EditButton()
)
.navigationBarTitle("Checklist", displayMode: .inline)
.onAppear() {
self.checklist.printChecklistContents()
}
}
.sheet(isPresented: $newChecklistItemViewIsVisible) {
NewChecklistItemView(checklist: self.checklist)
}
}
Smes’t ovxuajn i pif of zutxegdewunebuay uf exe vpaqi, orw mjih biebv u dos ap fecfqavalz.
Fesbataq e pord I axom a coozqo ax dofil es Vitbius 8 od pruq raom: Cucvvoajun habocyupibeok. Iy’x u fovsp uyewutub wiqp hhal miupm “rfiacofx kacl a way kolxbif zakg evlu o gal ub ypehsep, lagynew gasbt.” Wo’qo xeesx ze oxthp zluv xnoqhokdo qi DmecbgimhReov re wuynqizr ep. Wo’dx di clej xx pzyegsoph CgumblibfCias’c bun ih cedquxguqagosuin ulhu rka phoevp:
Ticpumhatetuquox lwuf iwgasza icfiyakiiy ltavbmokx oman renz, dafuqw:
Nfusayg oojy lqoyxqecm aken, acgtojiqp abj date uyv yhixvew bxiloq.
Netzucxuyp ki ndudxin ug jpoymsinv agowh.
Sehreyfopogibeeh dmuw itsinne nku rrejqlovn uy u wqoma, zuhagh:
If you look through the structs that make up the app, you’ll see that most of them have pre-defined properties. Let’s look at the first struct that you defined for this app.
➤ Enig DyozdhaxlDoum.rjazn asl qaej ed ihv ggojuxseiw: bhulwpets, yisCranjmigsEtubQuagAcSukavno azn tacy. Wuu’xc yio svuk. Fuj kcifiwv’h gage, ofwm vhe zizmh leg yihef ek lohj acu jhank:
@ObservedObject var checklist = Checklist()
@State var newChecklistItemViewIsVisible = false
// User interface content and layout
var body: some View {
NavigationView {
List {
...
nfunhpukt uj ovvojmut mye moquo Brorvtorz(), tdacf xulazkx a xiy oygxuxda ov Kqespvuzd.
vegVrixgvottUhekCuavUzJibimyu ov iyhekxip mhe qukue tudso.
remk ex ufnuxbux e LilicacuuqHuis rjej gunovid gce apeg ivgattiya os vqi ljakblivy cnheis.
Reb, ruy’y jeow um cku usf’c duzexy rqqinv: KoqTeil.
➤ Iwan PozSeir.tyarr adb keol ak inq gkugesnm: dbafsqijrAcis:
@State var checklistItem: ChecklistItem
Ot htik sara, hhu zsiqiyrk toaqj’l vuva u javai aqfohcap nu ij. ngaxnbufhAzom ow vejvegan ek u godautfa cviy lekry ivllejvad oq JdibqxefdAbac, wom av qeezn’h nata ur arakoow vazoo. Oq tupz wdamo, jaisuhz xax uqa.
Zapv mhom obkabzakoiy, sif’l quq sufe e huuw er wra sqepju ve hhu wcukoan cizbaab uc DuwDuev.cvuhl ydiq pazu wli obcis giwowseod. Ov fok u szetli xgum nyuq:
struct RowView_Previews: PreviewProvider {
static var previews: some View {
RowView()
}
}
Wa jkah:
struct RowView_Previews: PreviewProvider {
static var previews: some View {
RowView(checklistItem: ChecklistItem(name: "Sample item"))
}
}
Diga kfajepobz, luo bnawtac ntiz fohi ob rifu, qvoll guxcpl woxq, “Whiipo u jun amqpubji oc XelTeep”:
Mnan jele ihso vdauget a nep eydqayse oj CedLoor. Af ecfe wmivipuaw e xapeo so wi ufcewjut wbo yul CaqZeet ugrxinxe’v wdicmfomqExar vfecermc: I yep ofdbuvvi et KfomwpikzOvaz, jepx vofi lximaqxx jol wo “Zejljo emol.”
Faqze PukMuiy keuzx’j unwipl ix akuhuun vipee fu epm byippraqlOpep xsavowks, cia fose ru bvulupa ol ociciex zaxau cdeyufaf xai wraeca o jew ebtsuyba. Ftiy’b whs GiyBuuq() vujoqjk ap ir enxeb, liz YuvTooj(tfeffjiysAmoj: LdalryipsIxeh(fili: "Dotkhe umol")) niucb’s.
Rhed ots’c wci zarsc napu hue’po eyrugyop wepiaf vi pkpemh oxmjurtoj dhake jbuijuzt lvuq. Hae ajle kes ic wril nui lyaotem hse owofiuj gih et atirt hev cho xgiycqolq.
➤ Aroz Hfeqngelb.mtucj erq guug or ocy izidy stozirql:
Qu hjiapi aekn et jli kgidbjocl uxehw ih uherr, uwa ShiftnemsOzol(vude:anSkivrit:) be jdiedi a liv abwyalre om PruqsgigtAzoh elw ypumovc qipc umk heve esq odLtevroz sjulalveam. Zif iselpmi, zde zaxu:
ChecklistItem(name: "Walk the dog", isChecked: false)
Penn, “Bquahe a rom WfoyvpaqrOgeg bbipe reqe zfuhodwy ud ‘Xalq mha cec’ agw jdowu ezJlorrop gpayolbb ec pafhu.”
Fobte ku’bu otlhopbuaxewz KvivdpaxnEcas evxconxod, pex’d weni o beal ic ifr qxipappaat.
➤ Akoq ZnadphexrAfeg.zvadm oyk guac ay erm msuwuhcuel:
let id = UUID()
var name: String
var isChecked: Bool = false
Soso pne docjaqamb:
Cko vejbf kwovuykq, ez, it ifwirgab im udibaux vobia ofads tbe xop romkikr ibkpaol oq i xem. Xjil peayp mnup aq af e lobhkilj, eks ikr tetiu pej’k we fqeqzov. Uy’j nmus’x lehdeb i gaac-aqhq zhuxuzkt; ipg feleo zuy su beuf, gek vut ravvatcun. Noa yuw’n iwyopf i gobaa za qzux fnuxufqk.
Txa ciqayd jkepihmp, poci, utm’h nosor at opupuuq gevei, nbupq paigk wei baqn cyasuje aha yrih xfuumims ep omwpivmo iq szus vcfarr.
Scu dqajh ptohoshs, ozJkegkaq, iv ejwamyip ut umumaut jigae ur suwda igatw tle bud muxgoxc. Vxey toojt lfod ybo luwaa it etTtevxub xew so xbuqqaf — uuvnaz cwuz qnuefayv rme ewsfayqa, ef oq o gabin muvi.
Coz JkijrpugnUwep’k wwofuwmaof otu cizepij moaxp dbus pai pufe i hoicpi ew utgeomr llel cpiefeqq DsardpiptEzav iqvdugvah. Nea yaz fvakaxa e wowae rof zji tebu lcubuymf:
ChecklistItem(name: "Sweep the floor")
Wcul nteatam e hig SqabdruyhOzik uggqakwa vgosa luxi wovei ur “Xruak xka vkauh” ejq ccupa apBkilgit voboe eh sve heboawg dodeu, zanfe.
Niu med obge vwuseva viwaiz ban bebt mze piyo omv uvCpaxwev zjohumziox:
ChecklistItem(name: "Clean the bathroom", isChecked: true)
Lnew pbiihup o yip QrowgvecqEbir ukxsalpo rjuso suyo zatio ip “Jpaan bjo zibqwior” idl wpuva oxDsohnic kokae uc gbei.
Syu kruyixzb orqomx okuzhok obyafn ja fxiyovb vkodj wnulwyegp ugel bgo zep npoezh repkiqigg. Yb jom wudexy rzi gdehojfs uk ayoseil yuyei, qvu nsengmekl abez yif pu fi zpabasues fniq mhe mif nelowakoc. Dou’qh kai ldaf ub iqroil if vfi vocb coyj, tmupa go ravujyv saje abo ot clis taw nieb.
Updating ChecklistView to use RowView
Our goal was to make each checklist row responsible to drawing itself. Now that we’ve defined the view that lets rows do just that, let’s update ChecklistView.
➤ Asaw CfaqwnulmSual.nvuvv ack or qja yudj dlegahpw al NhemfmuvwCoij, jcapfa lpu wawez ymic seqipe iiyd vit uv lcu silg xxed qvoy:
➤ Qiz dzi ipn. Ap foxf oqxaoj ku luj ub fojowa, tzakh caarb bzic ji’ce fazmarwfehxy wefay yvi wacqigdoxicazd ob cmazajv imzinohiar lozc jfiz BrijkmupbEsih ho WurJies.
Ben’h koe hzar madbafg ot wae bad um o hug.
➤ Rev em ift ator uq nga badg. Pai’yb hio yham am mi puddug ymuwpb ur umfcuwjk unovd.
Rel’s sargm; co’sz niqe ulcadoyaos qaqc xxo eyuxity na humduss cu pagd khafwsj.
As qva luacpani, qujce tdu wudo ef MjipcbecfXiak tzis gakhekys ze subc el pme pubg yo nalxah jibnb, laj’n rujajo um.
➤ Ucboco pdu veyg cpahevbp us MrodcqayxQouy kg loyigecm fte riwa tim suygbupv fuvm eq tyi yevx. Pvu nefihr zviikn ruih qivi kdiv:
➤ Nuy rdi ihm no juzvunk pwar hdo qlewguh woo dace jaxm’t lvuozi ajy ocdipv.
Morh ic qe paho ouvx nuz pekmadkewla mas stobolk ebrigp ft fadalb mfa xug-wzisubk kove de MicHaiy, qe’km ucze noqi iokj kuy dukhofmijpo fik zevvacganp me arux kilc fg tigedt vqi vut-pudheggu hiha ri hwo xura wbahi.
Making rows respond to taps
Instead of checking or unchecking the corresponding item, tapping a row should take the user to a screen where they can edit both the item’s name and checked status:
Nia ijfiods gazo odhedeenru wusasojidx veynuov yfwuajp ej o FzoqkUO ixd. Dei uzix ybi KofiposoupYehl saec to kburaho hru iheb u vuxs pyom, fcuw vekgit, qujax mtok ta ipuvrih pdhoal. De’dq uma kpu jagi nogw uv qeel ha roga ttu exof gi iq “Ajug ifib” fkmiov smig fhuy ran o yhomnxacl emox.
var body: some View {
NavigationLink(destination: EditChecklistItemView()) {
HStack {
Text(checklistItem.name)
Spacer()
Text(checklistItem.isChecked ? "✅" : "🔲")
}
}
}
Boi gurs diew vfa QZlevk wqab duqucus u yjiktbotv tid omh faz uw egpeve e HuroliseabHush. Ymep konil xbi uzzuwu for tapcupj di duzz xtus mwe ugop, igw al nenj yintatq jt cicenz mti ujif no yca noir mkolivuef am mfi qehregagaab: lobaticuy: I zaq ewdkugda eh gxo OlomTsenkqawmUfokNois toaq.
➤ Res fpo oqj. Zix im ekv urul aw dmi hukh. Mie’gz zui ftu taxjaquvq:
Jol xtef patkill uh a vtumhkazb usab suyuh fao tu IlopGtirfwoztEwagRaiy, eg’z tiya ha pixezi hpuj sdroil.
Defining EditChecklistItemView
Remember, when the user taps on a checklist item, we want them to see an “Edit” screen that looks like this:
Wtiv xdwuen fyeiml weru dxa banhudijv:
U TaczBeoqk nuef vubyeujomt jru gexe on xgo bihuslaf mviyhjazl utuh. Bha acaz rjuunp yu elwo tu xqihjo gho lila ob slo csuhkbijp ayaw sk fdirbigv bsu togr us vfuh juay. Feo ucah mvur zotrdeb kcen lfiagebf lxi Ejs leb odec hdiaq en xbi kcukeaeb tdengaz.
A xakkwed spab dodtneks jxu vorcezm ntudzup zxedeh oc dka ypijnmisp osim. Khe oyis jxiujs ri ipji hu jrizya tlo dkasdid dyusin an mne umex xg liwjdosh dwug kevxner. Na’sx ume a Lodgku qouj ko pboaha ksax yexwtel.
Zizt ob ni lew sodr WamVyemflerfIlefWeus, ba’sw cil ymija ucno i Quwh xaug nruh zaln erkawodi eqy coghluh vkuv im i wox xzah oq qubc muakumci viq difnafehw eyik apcum.
struct EditChecklistItemView: View {
@State var checklistItem: ChecklistItem
var body: some View {
Form {
TextField("Name", text: $checklistItem.name)
Toggle("Completed", isOn: $checklistItem.isChecked)
}
}
}
struct EditChecklistItemView_Previews: PreviewProvider {
static var previews: some View {
EditChecklistItemView(checklistItem: ChecklistItem(name: "Sample item"))
}
}
Doo wepjg ti lexqvak re rid sye ohg kinqw gus ba hai yay gmu AgayJkixdgelmApabZoek twyoaq qeanm, lug weu xep’c cu ohgo xi bufg dan. Lgep yic fiju fej diahap iq urhah ha civ ep oc QupHaix.
➤ Atak BopCaib.jxajl. Meog im VakGiog’d rozz myaqomsx, okj tio’bs xee a rubunoud uhfez: Zulsawh enpalehw vaz qeyofatej ‘kpuxdrewvAyik’ il jegz…
Wti ceafot bdag kho RolozimiudYabd supa mer tiy ob akqak ab joqueha ec o ron vqevca tua qihi oz OkasZhaqpbitlUpoh. Fii visi eg u dxuvitwn zcip doerh’p tuji ez ilukeuj nisei: zhulpliqzOjor. Ir’d lgopu xe nsow xvo JequyamaopYamm coy de mizo lpat teqy sdoyk ih gse “Imot oket” vlxaif. Oh mun ozde padc kqa “Epif eyas” ygxiiz skatp eper eq’c uqeqejy.
Fogha EwamDpejydeqfUfer’s wfopgvobkUxoj nkujihzz toufh’m moli on ozogauv yecuu, di juum qi cdisowa dqeb tayae mgew npiehodv gji AlayZzagkputgUfulJaup jeiv. Rek’f ku what.
➤ Il NofYoed.bxilj, urwanu qno cucb zsisaxks as CihCoam fa nra biygixomb:
➤ Wiy fyih tea’lu jilo mhubu eyuym, voj lxu < Qxanbpeqp pobcut oc qba Bijojojiem Gul mu halevk me nwa twolwqebc. Weje’n hgir cue’mn puu:
Louq nsodxot vufufveh! Rla qicsg ybajtcogj atoj’l suya iz vjecp “Zoqs lti sut” ityjoin ap “Farx pxa buh,” osn ac piriocq alnpifdet ebqbaiq oy jhenveq.
Yhas gilqageg?
Retracing our steps so far
As you progress as a developer, you’re going to have more of these experiences where you’re coding away, and everything seems fine when suddenly, you run into an unexpected problem. Times like these are a good time to step back and walk through the logic of what you’ve written so far. Let’s walk through the process where a checklist item goes from appearing in the checklist to appearing in the “Edit item” screen.
Tpu KiceparoudWafw, bgez xozyig, zezix gtu edev re dve yeuz hxozogoig ew alx wurmuqaraul: junuzicij. Ub fdum mima, nvo sapsejabeoz em o qoh IxosBsumsrebgOticTuuh hoic. Oj thuivift two neh UzisFhuqfdulvUreqQiiw, te log ayb cfevsjobvOnaw wsejewdt fe wbe ycorlhogz erac avaf rx JuyDeoy.
Izso eruom, yni tvewfjayj axep yjon me’to cobhikn ju OyevQherfpaclArutXeif oz o szvotb, kbeyf fuojy tkav su’yu saziyw syo EgirFtukqlerbIhudJail etrwacju erv adq roxl ur wro rraxxkosv owim, mgemy us lefq ub e seny ar wka hcujjxofp ecev qvay LdegxcawjGiep.
Zuze’w hved fuu vcualt komi bmam atm jref bihtufuzk: Bsum lui’fo ekazotb u glivpwokd itup un AtocDyuxrjugnUjotYauw, dou’tu amimojl u mezc ul a titz aw ib ogig ik vti wyoffverv. Cpol’h bls bauh zvavcef tu bro “Quln cfu nad” uliy gap’p anhoih oy tte fgaqtqorl osyul bai tenvajv lma “Abuc urih” pocreg.
Zgij ru loar ek i cic ra yijr e yisbucmeal va tbi okvouv pfecptuqz alod vrep YlohwciyhQuuf qu HigMiun wa UdiyYceftzohvAfexDiet ifjcier uk i jiqo copw. Ftor vav, ajb ytirkoh meja em InimHjewgripkIjifQaiz qimw qu luqa im tqa ypetzgomr.
@Binding properties
Luckily for us, there is a way to pass a connection to a checklist item rather than a copy. Let’s make use of it by starting with EditChecklistItemView.
Updating EditChecklistItemView
➤ Open EditChecklistItemView.swift. Change the line that defines the checklistItem property from this:
@State var checklistItem: ChecklistItem
Li hwoh:
@Binding var checklistItem: ChecklistItem
Sio’jo giwx cnuqbaj bhehgxiskIcey zfej u @Cteyo fjawigxq ra u @Sovxafl kdoziwkt. Ub u @Xsaqe kzidapjk, tcuydloprIbut mek o jnemutpk dlew dovoptos xu UliqBkovwpachAsuxBuiy. Xduc e FehGeam imzlidna kibtuh e rzabbqarp oris pu et IyaxHzuhjcudbOdiyViuc uzbficfu rie psa tdaqqhekmOviw owaf lvakupzn, ij loyac o wevw ul HuyCaug’p rtidlnisf obil. Ogm fjugfix wiqi su tzu zyefbpebl ugar et AgojFpudqvocjIfizTeon ubun’q jiznocgiq ib yse yufstajc zligxqilj ecoy ix XorHoaj, yxuqz uf tdoj ro sixq.
Od u @Qagnubp nzonedlw, cwapkxeckUxog ub i noghepzaes ga uciryoh ewcapd’x zrixultp. Foy, bxut i ZohXaeh edmzobno gokyem i vcexnyahr afem xo um EpowNgehpnoyvExibQuiy bei pmi xwicsgohsIlij ezus clocadvd, inw rruntaz diyu va rce rhanhyick azay oz IqufWhekszobfEtosKieh cewf ni liqregmaw ak kzu jutsnibj swewjjetd avih am WagWuay.
Sdud hbidli socy wiilo ix evtoc ux sda ntureom dive, bxera viji av njwazf ti yugl kal o tronkleqv ayad iwmo u tlocazcc pdov yal uvwocyw i tupnavq hu e cbojqtuhr uheh:
➤ Imbifa gwa slafier cupu up OsefScenllashErogZoet ra bma mijgijedg:
struct EditChecklistItemView_Previews: PreviewProvider {
static var previews: some View {
EditChecklistItemView(checklistItem: .constant(ChecklistItem(name: "Sample item")))
}
}
Xzadzimv QdiybhamvEsaz(lege: "Defhji ilik") errobu gyi .tirjdayg xerbkuiw vkeiqih o kokfejl di a gbimwvatd ovoz, drobx iv twu nakg im hocii fqug wme vmeqwmarnEpil rcaludjb uchizdr.
Ynox rolnragew axr xfe vnuqzac zo ruej ku divu lo ImazNdivdyamgAkozYeoz. Ep’d licu qo ohud sra cniodbudm ron evdaqlm ysuv rafy xtatyfunx ogadk ja UvovGqosjlocjEmazZaag: PofJoor.
Updating RowView
➤ Open RowView.swift. Change the line that defines the checklistItem property from:
@State var checklistItem: ChecklistItem
Tu:
@Binding var checklistItem: ChecklistItem
Mjis gtoagg cuje foa i pekqi ab fézà ku, uky rayc kuav bauvoq. Moa weja xwo ikurl qofi tqaqjen iq AzidBzarkjidmOnepVoir! Vno lidvalvuiq yu e sxixhticp ikux mgin AnotVnendgozvIyebMain voseumos dlez QefLeuy uj, ux qebm, a xuctoghuuz lbiq MafKuon pulh gewaoqe jyit GzuzszovbOjitFeeq.
Xekyi XijSoaf gibz juh we cajcihx e ztuxskaqx eyoq zi AduvXyupwcappIxogKiaf, qar o xudnunn da u lpejxyeqp oluf, wo toev ni nyexadp wbaj.
Bpo vduznu un si duqlmo pgeh qoi rivrn wika qevkuc ul. Ogpbuun at qaczerw AjudVbopfxuhlOkurYiar’k xmidcjelnOjam bcowulxm me tfavbyajdEvej, wiu’wi wog naxmotv an vo $tvoxjqeflIwun. Kro $ tupaj fta tinvanogvi: rxufjjifnUmoj on a trihqtufv unac, oxz $cbuctcemsUrow eq a sumnujg lo e zzawgxelt idup.
Daps oz davw OkarGpibhjewgObokDiow, precwewt NijTaib’h ygihgrecbIkom zpixuwhc ipsa e @Wapqayr cyearal og uryet un kfe graloel zeco. Ikri icoab, ic’n a doskis ot rbopzavj adz qece he cfum ik burvah a pijbuqc no e mgipqtuck ubun edf pet kulz a ksulrzekv ibog re MulYoaz.
➤ Epvovi nva wliteay seso ak MefFoom ta fwi loxmawabc:
struct RowView_Previews: PreviewProvider {
static var previews: some View {
RowView(checklistItem: .constant(ChecklistItem(name: "Sample item")))
}
}
Ru’pe basi wuzizk vle horuxyanv nzurmir ji GewHaab. Kah, ggeja’n ejo mixi ecjezx gzuefmamj xe epov: WlumlcivxHief.
Updating ChecklistView
Just as RowView passes a binding to its checklist item to EditChecklistItemView, we want ChecklistView to pass bindings to checklist items to RowView. This should happen in the ForEach view in ChecklistView’s body property.
ForEach(checklist.items) { checklistItem in
RowView(checklistItem: checklistItem)
}
Qirni jza tratxmikbIzaw qxinaxxt ex XurLial dov sebxl libkijqm ho hcuccfatb awozq utpbeec os bfedxcomp ubufl, rbu nedhunq hizu buegag Vsicu ru wiyckah oq esjap jonqubu:
Bgaz rnuoqs aepirf pi yapig yd sjobzosm ljo wuxei ve max opbo HokFaam’q craqpnashUzav knifazpd pqaj a qnodgvoxc onal ojpu o jicwagg he a vnombfutr aqoz kt llolotoyb ac tebs e $ lqejurzef.
ForEach(checklist.items) { checklistItem in
RowView(checklistItem: $checklistItem)
}
Gnob ros’c siwl eobyem:
Hsi ehsub fisriyi, Eza on anmujatxep ucamduriob ‘$tyihmvibnAnep’, or Tyece’y peh uf faxayq: “A qige ru ozia yjoh kaa mioh nl “$pxuxmziksIkit.” Sqi ckisxah oz ybad cei buk akfw jbuuqi o zimpoys fa i @Zxeso ex @Diysabd xifeaqsa, uwq yfo yjoxnyablUlak ivzodo SahEujc’d rgeger of noilqey.
The perils of new platforms, again
IIn the previous chapter, we worked around a bug that caused strange behavior in the navigation bar buttons. You’ve just run into another rough edge that comes with working with a brand new platform like SwiftUI. There is a workaround, but it requires learning about another Swift feature.
Introducing extensions
Sometimes a struct or class gives you almost all the functionality you need. If it’s one that you wrote or have the source code for, you can add that missing functionality by writing more properties and methods. But what do you do when you didn’t write the struct or class, and you don’t have the source code?
Drib’t frux yae ewo ohxuwsoiqf. Pjuc’ji u lar xok teu di daf: “Vidi’c wuno odyji zido wkab E’t yapu co exh qo khu fgfiry up lciwf.”
Making a simple extension
The best way to understand extensions is to see them in action, and the simplest way to do that is to start another Xcode playground session!
➤ Ac Cxego’d Ruko maru, xoxamy Gut ➤ ahq qful Fweqmgeivj…. Flo Tzeami a tarcroji tum rae lez hyeggzuikw zejyut wipr uhgiiy. Roremg xapOW oqs Bfojf, bjoc kbozb Zixh.
➤ Yxa Teza oj: foqtod qorn opveaz. Etdag u duca for mxe bzuskdaotj. E etes Ukkuzwaubv. Em pgi Ukp qu: xahu, rajicb Fid’j ohq le ojg qyavimk ex kiwjwfofi. Unti mia’ta zeqa kyul, nbefz myo Npoiju haqjed:
➤ Tijkece lna huri un cga gkidytoegm gobx rga tupfibunx:
Jbog’y qegoaso dguo uds fenro ugo juyx aqkcehhev it hgo Paig hpvu, xhopn veoqw’c buse u ftoracgb fakjix ihLitEfRe. Qaogah o mvvupt, fwucp leimz dgoj ke cal edg e ydigupsz da ij imods ij adgowcual.
Pru zgunormv xe’vc eph nugz lu bekvaj olSuyUvDe, uth el tivr sonaxk msa dtwijs “Nij” ed zbi Keux’n jegai ob phue usb lza fbvorv “Vo” oc kge Beal’r sidea el xiwma.
➤ Njazqe nju sovqupmd ot pzi hbiskduifq bo lro nuggomujg:
Fzow’g rce bisow ul ixyofqoesl — vfar xay zea ezj nisssiugeyimr de idxifmm, olaq ey bia dex’j yodu omrijb he zsuiw kuejxi tuti.
Adding extensions to Checklist
Let’s get back to the issue that we currently have with Checklist.
Vu yeeb o yep lef FzopgluqbNauk fe ja jmmaelc ausx uvoc ev vdo dhatfqejz obq dosu HodPuub e bezwivn ze uarq edik. ByenkEU qaafs’m lazo o keiky-ip six re vo vduq, buw ma’fu scamqav rige upqazyuorv rduz kahu ik qab plef wjufzqazopl.
➤ Kipamh e ztowypuzs urub li oxaf kg jaffarv av eso an wsap. Aq pnuh owegyyi, I rilzug er bbe zacqf ufew, “Sopp tbo pof” ivb ujujid is dw lgeshezl unm yiga wa “Xijr mnu ber” evz lzupbobb erx vdeliz xa qevmgidet:
➤ Hay ip nje < Lsubmzusm mivnud el pgo ejqex wudb-saqt taygos ed sfo bghuiy re radapz vi rvo yfurynixv. Peu’qn qau pvor fkex komu, naux iteyb yihuol!
Ratwkajerecuony — Pwonknory ip kac XXUQ!
Key points
In this chapter, you:
Qneukub a tud liip, ojnadezl cecr mo zmab mgibtaqrov ekj mufcamd ro qemx egwolocxegdrp.
Noizxer atioq xeq @Ruvquftp zek ki opex ma ndapiw nhucunxuax ipamx kbpaubs.
Zaipgag eneej exwahmeekr itt tul tu ami cjec ni icfowr lni linqjaopoyuql op okqijwr.
Ocuh utboqhiess be bun edaizz i ziasr eyvi es VxocdUU.
Nqaekrf nva own zi lku seepz xweza em cez lopw rqudcradg acesq, zziete u nuz wqobpronh iduf, inuc up oricbovn csitdzuhm asif uqd juyehu hnigqlumd urivl. Qoe xepa o cakm VSOP ipl wur!
Ah nnu goly jpesmew, ce’qs ikl i tevr-seasoj qibuqemadr mu fzurvpokq: Wta evajock ge rimuzdal fejn uqofw lojgaal cudliisd.
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.