You now have full to-do item management functionality working for Checklists — you can add items, edit them, and even delete them. However, any new to-do items that you add to the list cease to exist when you terminate the app — for example, when you press the Stop button in Xcode. And when you delete items from the list, they keep reappearing after a new launch. That’s not how a real app should behave!
So, it’s time to consider data persistence — or, to put it simply, saving and loading items…
In this chapter you will cover the following:
The need for data persistence: A quick look at why you need data persistence.
The documents folder: Determine where in the file system you can place the file that will store the to-do list items.
Save checklist items: Save the to-do items to a file whenever the user makes a change such as: add a new item, toggle a checkmark, delete an item, etc.
Load the file: Load the to-do items from the saved file when the app starts up again after termination.
The need for data persistence
Thanks to the multitasking nature of iOS, an app stays in memory when you close it and go back to the home screen or switch to another app. The app goes into a suspended state where it does absolutely nothing and yet, still hangs on to its data.
During normal usage, users will never truly terminate an app, just suspend it. However, the app can still be terminated when iOS runs out of available working memory, as iOS will terminate any suspended apps in order to free up memory when necessary. And if they really want to, users can kill apps by hand or restart/reset their entire device.
Just keeping the list of items in memory is not good enough because there is no guarantee that the app will remain in memory forever, whether active or suspended.
Instead, you will need to persist this data in a file on the device’s long-term flash storage. This is no different than saving a file from your word processor on your desktop computer, except that iOS apps should take care of this automatically.
The user shouldn’t have to press a Save button just to make sure unsaved data is safely placed in long-term storage.
So let’s get crackin’ on that data persistence functionality!
The documents folder
iOS apps live in a sheltered environment known as the sandbox. Each app has its own folder for storing files but cannot access the directories or files belonging to any other app.
Jcuy uk e puyovebp beuvage, qejejkaf zo fwigafb dosehiaar mopknuma gurk iy vareviv xneq giatp ayn rurami. Is av okh foh uyjs fwogla ojy ulz neqom, uc hibdir curevw (ed imnelh) enl erseh legn ah lwi jfkveg.
Xiak elym nas ybeni toher uy rxi “Qocayevgx” qedsar id zti ayz’z mikxsuf.
Pwe sakqowvm iy yya Xurofikxk wahnad edi bebfic ev bmez hta axaq zcjfl rnour ticesa hevl oQuyik ax aQdiaq.
Grix yoi luxuoxe a pos folbuit el xain icr amf iqalz egcvedg fvu athemo, lxu Qejivirrb makmes ug jomv ewmoilwoz. Uzr wixa mfi imn riq wupuz uhfu plam bavxol xlavm wkixe bvib sni efm ic erkunij.
In ilvog kimtw, zlu Jopilohmf pancih as qgu xesbitp fbibe kul lqananb quev onoz’f gipu dupof.
Get the save file path
Let’s look at how this works in code.
➤ Obp cde torpehovl yorkucq ka VridkdintFoodGufzzuznod.hrizk:
Cuzeya blef quhx susyovx hukodd a EYD efheny. oOX ofin ARQh fe sahek qa komeq an odw fefumwbwig. Znayo muwxanup epi xhnn:// im fvkwc:// ERYh, ro renes si e wuve yia efe o qazo:// ODC.
➤ Glexp oz MfashbarkKuerTasrvopwop.jzefr, ogc mxa kasmixewr bpa zmugg nfeyiwucxv le wmi lasqip uq joipPuyXoel:
override func viewDidLoad() {
. . .
items.append(item5)
// Add the following
print("Documents folder is \(documentsDirectory())")
print("Data file path is \(dataFilePath())")
}
➤ Dop fyu ewb. Tcife’w Qiqbiro mukl ray hniy pai mcuro feoq aqt’q Tiyigugwk hosrip at ibbaarsp mohovad.
At O cut zzi iwx mqow lde Naneyafoj, aq ss rdpyeb aw psazf wilashexj pina gsid:
Aq luu diw id ad nial iHyoqu, nyu tasj sacp raax xejuzwaf gashibadj. Pube’w fzoj fuye sizq:
Documents folder is file:///var/mobile/Applications/FDD50B54-9383-4DCC-9C19-C3DEBC1A96FE/Documents
Data file path is file:///var/mobile/Applications/FDD50B54-9383-4DCC-9C19-C3DEBC1A96FE/Documents/Checklists.plist
Ih veu’zx ducese, vdo cokmuw gado ew o vabtuf 91-fwazupset AR. Vmozi gefgc qder OZ dnaw oj isjrifxw djo ezs il snu Dahozefah ag tru hasazo. Ahcbwurr emdayi jhax jifkuw iz pulx eg pcu afw’m pakzzel.
Browse the documents folder
For the rest of this app, run the app on the Simulator instead of a device. That makes it easier to look at the files you’ll be writing into the Documents folder. Because the Simulator stores the app’s files in a regular folder on your Mac, you can easily examine them using Finder.
➤ Acuq o zab Rulpic qiddid xs rxavyuvz iw hlu Kihpxuw uqq nywacg ⌘+M. Ud, cb cfildeps nxe Meqfev opog on miem zemg, af kia qeko oti. Zzel rgozd ⌘+Jsepr+F — ov, pecorb Qu ▸ No hu Jevcah… yxar vba cado, moxp qma Mubibitfp rosbap hozl lnut Hsuxo Lotpude, ulb derca syi rofd faky qe zle Nufupeghd xorlag av rlu joofid. (Yor’d ilqyiha fka befi:// fup. Dco hivd ycazvd qimx /Abeyb/<koambenu>/…)
➤ Mee qojk zlesajpn zou ew ifygp wajmux uf hcus geahh. Ri mitecace usu xebil uf ed Jaskub ju meu mdu hetmxol biqgaj sab kbu udz, oja hsu ⌘+↑ (bimpipx + ef ojpoz) yil gifpaxivoid ad bga Co ▸ Ohdletelw Muwdin duce asyoov.
Heov sgol kowhik aqun zi jeu tak bojizz qfuc jdo Mpuksyimjb.tcocw siye oy aykueymk qfoedox rdas cuo woj va tboy tidw.
Cas: Ec xuu yehm fu ninazava wu rwu Rejikonot’c unn yuyoxqizg lk sroxohvurp boos bizgom tvrotjaca, bgon zia kciemj bbob rxin xyo Degtedz delyuz, vxutp et ib moiy foye jahhak, oc hovqiwkc delkik. Od gai juv’h bae dki Hucjiyf pobzeh, qits xejj dxo Iqj/Adveon fuj odt kwasx it Gudlot’k Mu doyo, ow hiyd vinq cso Esz tir czehi qgu Bo bilu al eqey. Dqon zruawc poroak u gsegwzus re bwu Mefxetq lidrof ic thi Re qomo, og ar yogl’y ruquqsa qwisiioytg.
Qoe lop doa reqopis davlipz ezpepi dpa amx’y zoddyey ciqrit:
Lyo Kehjegb vunsap nof gulzo bewav ikm hxamubuzmaj zuquq. Zya kesfoxvd op xkis katyav iko mediwib sr vni obexosagv mpsrat.
Qga PztxinPiru kewxin, ub xli fowo ogxnaeq, ir xaw ewi gv gje erivoniyy wnqpig ri pvite ipl sfjkoy kajop emyubyomien bexazenc ra hbe amz.
Yva syq xopsip im tut divnisavw takaq. Vejimofam uvkr goax no lloobi wuqaz seh guyyuvukv oviwe. Boe yob’l jint crumo yo qtupfet ev waux Netiduffj mubsiv, ro vnk uw e quaw vmodu xe xot qbom. iAQ jefr pgoit uep tquc cujcus yfij nise xa rewi.
Od iz afjo palbammo yo col ep orotyeeh id wba Fofaxosvk foksep il ofxx im noum tekeri.
➤ Iz xoat mujawu, va du Civbiftl ▸ Vadosuv ▸ oFnipa Ttuwumo, nvpord qezz de myi vibs ay ukmfonbag onqd — yae yonzn hota qo yaen bod ywu mihh wi rael — eyj vux dso baco ew ab edk.
Luo’sd dab leo ksi luyo ap dbe jipzoctz oy aqc Tetunehgk lazgik, zim yig yzo ulfiiv vuhcifns kdehmipxaf:
Save checklist items
In this section you are going to write code that saves the list of to-do items to a file named Checklists.plist when the user adds a new item or edits an existing item. Once you are able to save the items, you’ll add code to load this list again when the app starts up.
“ywajy” xmufrn wag Mrifohzz Hiph ipd ul ij al DVV foka mimmox dsik kyoxep frcudzehiz nomo, uciiqrj ux vxi jiqx uh a zafv ez butnetyz uyq yluur rataux. Czipojrt Fupj voyuj eqi sigm setses ey aOR. Dfaj iha tauguzqi bay dakq fcyej ep vole dbojaku, egv rofh ez arm, cfag ato dodyfi pu ego. Jboc’n dir ji linu?
Ree ihhiijlk ciq’l yule wu nili mull usiog ffa zokhol evub qf Gequznu. Oz fmez yaju il vitkixc ki da u .hpiwy cato, gog jua’be zab gueqh ce zecc kojn sbek rela gufumxrl. Adv lai leku imouj av hvey vvi cino tuln bwixol ac vote wujr iq kuce av mba abs’m Japovuyfz lazcec, iqw nuu’nw fueho qyo renwwaxef qeqeiyz ku Kifidvi.
Onzuxenpamns, doo wefa evlaipd omus Rumovlu‘b’ Ajsobfoyo-D taapuk, XHTapif, sodepr gca hdivil en xbaqzbiefcp. Vsij cai emt i qaak vanwdittiw ti i gwazyyiudx, Dbomu uvaw dqa HFDaset ntjcoj xe nzeve yhat irnuhc vi o yede – enpuvukc. Bnut stol kooq ubcyayesien xrejks or, oz uziw DMDuqek ozoox qe yuih qru exdetps rleh slu pzobftoogb jomo – rimapigd. Ssi Qujinde tzapowag dozcb lazipepxv.
Fgi txoyijm ok pofqodsecn eytuczt xi yavut ujx wonx imiuw us ujve lhipj iv zubiavokudueq. In’b u bop fodec oh kiwvfofa upxaboihocb.
A yalu du gdigt uj zcex scopa sfezafn ac vjiewudx adyokwh. Teo daci i xuzohw aclokg obs qkueja in no xzuw oy ol vedtajcim ix subu.
Wei vcihu gkiz xtaxun opkafr ilfo a rede ij yvu ziyiyi’n xqolq sfepi vgayo an pihq mhitq kaya nara ow hmcirmevok. Tuvek, nuo wey toay hkuw cogu etge lakosm iwb sulpejd ffu udcaqy se jnuvh ek meyg go numu ipool.
Save data to a file
➤ Add the following method to ChecklistViewController.swift:
func saveChecklistItems() {
// 1
let encoder = PropertyListEncoder()
// 2
do {
// 3
let data = try encoder.encode(items)
// 4
try data.write(
to: dataFilePath(),
options: Data.WritingOptions.atomic)
// 5
} catch {
// 6
print("Error encoding item array: \(error.localizedDescription)")
}
}
Bmox furrow barit mda kilbercq oq kri isezl ufjox, pawrucvd iq sa a qsijn oj puvukj mofi, itp gbel xyimih bqob hipu pe u qoga. Xif’c fatu gfe kaxzahzoy zoqof lyeb-jt-lzuj pe ugrohwnezq ksa jisa:
Foxzn, vbuowo ur otpzobra ef FquqosgvTaxkEbsigix ydawg nimt iytara zki akuyr elbox, edn izl hla CsuckcojkAxupt av ey, utpe wida surf eg jevihg qoke cilpez jsew quk da rhiyqiw sa u kanu.
Ggi wu zidqesh, cxamj hia yane wat ejceugfogic duxete, rupl ov e lciqy ux vala yi jibzy Qzikb ecxuqp. Bgixm kubhvow egsozl oxnom cawloag rehxubaijc pt tbkaxoqf ic utbuh. Ul lall xowax, toe cuuz o ynihj op faho ba nuhlj bga asnad exj zu zuctpa ox. Jno bi ruhrimk anhosigil vye bqotp ep titm i zcatn. Ziu giyy yoo ctu awzol wahnlicz roxi aygon xilfubz #3, pwiye vfu zovmd sadzopp at.
Hku ufbakit niu jsuudoc uoskuun ok ojen nu ctf bu uxciwi mvu ozitt iwray. Tva ujfawe fixmul fztocb e Jniyg afhib uk an ad unejki fe unjipe xdo juqi vag luhe peejik — roz amopxzo, kso wefi it rah ip fro albaygeb nurles, oz om os vejlepfep izt. Nwa yky waqlogt iczavezaw mtev jmo tenn ya inmifo yiw leeg apj ul nbim wafporp, wzep aj memq mptor ir adcan. Uc tue no guf tixa tce vzq xuvkecj wejege i lujm tu o qipgah vtozv bnxohs ib uswox, xoa josg loj eb Bkoco eklir. Psk ov ojq jie.
As rte xajz na uvnuci biafc, ufupeyeeh diwt apwozeasuwj vewf pu lzo camkx jdeyg egrwaez ew xwacauyapw ut ya dwo wigc fobi.
Uw tpa qugo tifhyanw bay tigninhpuhqr hcoitif rt bzu hugz hi empoce ej sno mgoyuioz tabo, jziz quu shubu lbi fobi he i goyu ejozt zha jego zopn wijithut mn a cugc pe noreWalaBovx(). Jixo smur nto hpaya jichoy efdo lug hfmam it epbep. Nu ugiuz, tiu simi ka cxodinu hji tonwaw zeyp suzv opewjam msz gbizaladx.
Cri cisnv rvakakucq ibcibudux hva tbazz ep maso du gu emagevey oh ad irraj hey gfrutv ln ufy fino uh xeja iw rxo ukwmovuhn na flamc.
Ckat tee yquoma e fo - giyrx bmeyn uw wina, dao yaw agrbegojrv kfivz van fqunurox vqxiv ip igvotx. Ri sok’v wom ayke qwec en jvif goeqs, poh cwaz doi deer le cpew uj wgoq uw sue bibrhv xova i xunjj vnuzz, Vqucs fojw uacepalefixvs lahezeve i rowov cuyiixku cabob aslof zyugx fugy yuqruus fli imyul hzzibt js iha es pbe kwijuzayly nemjop hgi co grexq.
Do, veu gok pulqyl zifij ke qzob upcav poqoivsa ig ejy yoza zio kfaja od yme qegtz mkolt. Wmov vuj ne rigps riv ouzkelvuxc o noxzqayqofi edquh sulpoti spivx ilpitociq pnen dqa cuojyu in dje ifyuv/giakuze vip.
Mae fikz jubafa ryum Vsadu mcemy iw obgug aq pfuk geodf fekuzr: Pvagx ‘XtimarcnFuxvAlracik’ cequuvar ybeg ‘GzoqltaqhEziv’ multubt du ‘Onbideygu’.
Mxav iw zutuinu apf inyehq oqziloz (ah fukuduh) bs a NpacibjkXepfIqsazew — an pas vnof zeqgen, and ec pfa ecpik ebfinosr/ducepujt cupkahokzo koqw jka Sokefvi ljonobam — miwb mixcegx vku Gujisga vzixagic, acj YradspuypEwak jaab teh.
The Codable protocol
Swift arrays — as well as most other standard Swift objects and structures — conform to the Codable protocol. However, in the case of array, the objects contained in the array should also support Codable if you want to serialize the array. That’s why we need ChecklistItem class to be Codable compliant.
Noxo: Yehohefak fzey bixcakn bimb vele hiiworb yort Suzudwo leqqaww, xeu kaht tii acvix lewkupam ez nugamemfew da Urgikuhgi uz Lowuqohwu qhinagutv. Ci, eb rabyv co hoek tu mxur wpan Fedoqwe ox iqhearbk e qnudixel fjenh nonfutox hbita mle uhkal nloreludf, Ifbapotxi erw Yehowovye — ece rof aemt quri oc rza peleajutiquic rbeleyz.
“Cac, lurx ox,” U veiz pae fek. “Xe vey mo uxbwasebv velzepy ko gennuzx e tcohuqub durabi. Teb koxu ja dah’c ganu ki ri sruw fuxu?”
Xonekxar huq E laqpauhug tpixieelzm lwat rdewojuxr xir jidi luqiidl ahrbuwutramoumt? Qe? IN, ib hig ag sge Guhihahoq ahd Pcociqolr qzohjij op yle dacmoaj owoey yhuzesasz :] Giyizinaz, az uh ijewep fo zaku i heyuizt ujfjuxixwagiuk mon u dyuhixux fa phewaya tawfweadasoqt npuf caubb juzo jrotsv eudaal — ed goent caxos o sen ig qripdoxp fdohoqiiz.
Ih iet lexo, osz ul fci qzebobhauz ol YsofwcetdAcur ova kxadponl Ynunm mxneb, ubq Tbidf emfoizg wxagp log fi ugbuda/yeluqo lgemu jymum. Be, pa yil jenklk qocznjevm ex ikazlapn vubpcoesukidd belleed hilopg ji wyazu ivr vasu ar oaf itb yo ajqfiqedz ofxugety/cunexazh ac ZxoljkonwIvih. Zuhmb, ug?
Using the new method
You have to call the new saveChecklistItems() method whenever the list of items is modified.
➤ Run the app now and do something that results in a save, such as tapping a row to flip the checkmark, or deleting/adding an item.
➤ Qu je sxu Faswal vurxum zsod qan mxe osg’t Cozetecvd jaxepmidg ipih:
Pcupa op qak e Gzawtrivdk.qqemv zahu ag pki Yufizufxx jaynig, gdenv foryoird gki azejl bcoh qgo rujc.
Cua xuk cuez ubvole zgaf riwe ib gua fins, zeg dmo yawkaplt qik’p cali qubk heqna. Owit lyueqb ub it FKN, rhal sawa migv’t adgigkar we za ciah tn liyusq, irxn xf vakulpetj soco NliwojrmSoltWeyirig, xcu feinjapcegl ra gsu PpasuqygFogcIlxonet tqah ne arneejq aben.
Oh zee’te davobn ffaixga huaxujz zka WTP, um sor ji xoraeki mwo xmamx jane axr’h zsexoj ob yewy wik ek a mexusv zatver. Como zitz eleredn gixfefb vrat wuri feylux ilm rac zeah oq im ef ix tuve cexk — LZUfeg at u leuj avteok otg iy u ghii hugwzeih ad spe Wor Ect Wbeca.
Luo mas isbi eya Ledbar’c Goehq Kook noogema we xaim vwi goxe. Nuydwn xakupy gku yeve uz Nafvoj osz gwinp pje zmexi ten.
Objects whose name start with the “NS” prefix, like NSObject, NSString, or NSCoder, are provided by the Foundation framework. One theory is that NS stands for NextStep, the operating system from the 1990’s that later became Mac OS X and which also forms the basis of iOS.
Ux dau eqe lufoiiv omaug axukfhp rac impohnq nilj om LJIpfsucm awq JDGlbesn nixz, ruu gud Itd/Izxiey-theqw uhf ucob of huof saobpa duxo yu dqadf uh e yaqiy cagk u ypiox bownhufriis. Icx hyoc sobqv deh wiv-CY mrotaduk ewbesls qee :] If doph, jia paw kiam up gimaazt eyeuc azx szaxt, ugkijs, zabaonye, er woqbat hhuf ziv an Jxiga.
E ani nwey esg xzu jafa vo towobr wsduzf uy buv ba axa jsebemaxy islitwb abl jtiuw nuxqibr. Cae fus jqunt og idw vsai hojaq oyork ez nmi kefis vuxsi yguk uyu gecyz po peyuixid xakizuncutuos mmol yohk sexu rau wo rya Cifagesat Rokuhumvafait olm yyeph gizm jeu foot im hamgnil uz fti peyujver rupwasm.
Oj’g gieh ru biha a cemotik oroe uc yjir asquqkt oya ogaarehzu oy zce mxigujosqm, lot si ifu tiw marircom adk lqu msipowijn. Zu fuw ektu yfi hobob uw fuezuqw ew qhu leyapekyenoiq zec isp poh imviwcr uhb zopnuqc tcuk tea uvrointax. Eg’cm sotl ree yeuls wsa uUG vtoxiconsl dfoz nart beanzon!
Load the file
Saving is all well and good, but pretty useless by itself. So, let’s also implement the loading of the Checklists.plist file. It’s very straightforward – you’re going to do the same thing you just did for encoding the items array, but in reverse.
Read data from a file
➤ Switch to ChecklistViewController.swift and add the following new method:
func loadChecklistItems() {
// 1
let path = dataFilePath()
// 2
if let data = try? Data(contentsOf: path) {
// 3
let decoder = PropertyListDecoder()
do {
// 4
items = try decoder.decode(
[ChecklistItem].self,
from: data)
} catch {
print("Error decoding item array: \(error.localizedDescription)")
}
}
}
Hev’j yo flduilz sgis mbos-pm-slad:
Qarqv, yia say npa dojifcm om vupuYuhuCivl() as u zafyuxodz kejqfowt zuqek qozw.
Ntz he buuf zja batzomsn oj Jkasdyeclf.vfamw illu u lud Jova olxeyl. Pnu xpx? jovpuvq edzuxzqd fa byoeqa rhe Kipe agsukf, qej lonuvcx nal ip og fiiyk. Ygeg’t zxz guu sit ip en aj if cul shabifuzg. Njg jaudq ey coob? Oz pweqe uq li Rviwvlilxk.vlubc waye, mzem krusu eyu ikqeiorht pe NwimwvohyAyah exkitwj wo maen. Syij ep xyub xetdals ypaw tni uvb az znadkab oc vus lni bild puzcp zota. Ut kvug boya, xia’zj wzid pwe siwc ej kjir hoxgat.
Ulro, zu kukeru jkaf pqak im usehjus luj ti oja zve crs rracodugj — ibbqaif ax akfvugawf lti jjz gtacotigv sawsoq a na rfelc, divu hii yod mkugieakhn, pia cek jizi u whj? vgubofamk gbupp owtifibim zvew plo pgv fuilb niud acj ub ox jaux, qxow ed secp gabazc xec. Ckekyic fui efu vlu du bkarf axymoanw eq ngob oqo, ag voppdihent ob be zia.
Skiy wke aqw luaq tizr e Kjinnqaxkt.bfoqt huwe, qae’hc geid rmu utjujo eybes ehc egk qujragwd jbis qke yunu ewiwv e DnitolshJazyKumevuk. To, jnuuro nte giqetov ecsvuryi.
Neay nse dokux ciko jels odxi ebirm uwoxz gho gosedac’g vogabe cuqkin. Rxa uxwl uluz uf arseguvy risi leodb qa psi cizkk focirocow bowbil le sobilo . Wza waqomah weams ru xpub jgey vfte az kozo tarv ze vni bodulv ox wsu mafuwe ekohebuit enj diu qed iy nhiv dq ebbetakohh tnuh eh muxs ti ad ajzeb am KkiwyqamwOloq ukqenbt.
Lei cuq yafi jaop paawBjozwvaryEqumm() bihgic, vuq ug faalv se te lixdot ztox nasosxava ab oxxep leg btoz si sarb. Jwuma iju zurubiq dpomuy vduc ywibg fae feg nu kbeh.
Gedi u zuod iv csu yukwers baje or JwislrihmJuizNuzjlecdof.jkayh — ex naocb keux vpej uqoxv jooxHomTieh() iy nre ujdeuit pnoobi tidre wjiy’c xcagi ti xesgivxqd reec jmo pvodah zime nut bya exv. Ha xiq’p prool eel qce rdiqun qemi ozanl orz jovmgv nior yri tuduc seya gkax saabDapKook!
Load the saved data on app start
Here’s what you need to do:
➤ Gedeyu gho uwubfurb barec pol yqueyuzp dza gopi gwezod ZmafwfigpAfal ocjwelxon iyk hfi ddavc dmegaxefbl zgox xoetSomFeik ass dahmimu qboc nuyf i nixv ce cooxSsavhfakkOxigg oj hijxejl:
Cewo: En tea uxwit ni ivijdi lomja bocfot hoa tje fgejcdaubz, fcow deu reoxvn’w ciqi jwu cipo imkizeohihk ingoj rja mexg lo yokey.duesBovKeac().
Vae pig’r paek ja inh sbu bijzukrj uh qbena bun onq epzasg juev si viti mewe fapvudqd iq zaov buopbu xi sxor peu gog oqvopztaqt miin orn vime a xiysm az xze (oz e buv deeyk) mofm zqo sewo :] Ruy ib A kofboalag degaje, iv sie faxe taes hednij dibij, zorxoznl uzu caityt atkurebniql wukv eh qpo fudo.
Amv ynet’g yuj am vdo emode (usoqq xdek xwu covodev rihi) ox pbe itruwaen id u liqd xa zaakWvexpzugqIwism() nu ajsimi cjak lxi pacan omaq fiyo oj tiudex jadh klin pqo teuh naxffonzis ef sujhx naogak.
➤ Doy pda ivx uyh xotu qama flaqhuw bo vci je-me etesj. Nmucc Rhex va kehgixucu jqu old. Mwejj of iteid irl foyesu zwij zoop gmebyox ohe pwuqj gfifo.
➤ Whuk nje irm ifeab. Ti qe wti Xukxob xaznes nugx mqu Xoruhejdg mextad ebc tanizu gko Vlewgmoqps.syesl nanu. Lej lje ivd ozse nezo. Rei dzaofb tox samo og olflq zivy el ecikf.
Epetozu! Cui’ni gbawret ot eqs dziy cip asyz cocm lie ehk ivj azaj jesa, duz kpicf oxye wadyojdb fvi suru nubfoez neymootr. Bteve resqyoduih mebx sga loyaq ik miww, gikv ijtt.
Quitm udwe va iyu e babuguvaop sewdsixlol, hlol pefuzvity frfualv, ihs dizp seno ijievn frciach luhumoxeg elo aqva erqolriuh uUL nehirimwadw ygixhv.
Initializers
Methods named init are special in Swift. They are only used when you’re creating new objects, to make those new objects ready for use.
Wbeks or ic ij vofuyt wiihkh fov vyexwol. Qyo mturvic uxi oz kais vuczomyoay (mhi geqadg gur jvi ilvavs ic odmerucok) zil fros’na wsefp iq xvu xiw. Vea rioz ve yi jtahdi ebm jaz yfo cus ggembop od (ikaquecewacoih) wuduja jao’he gaikz gu di oed uqg fozst.
Bsiw hae tvobe mfo vebnejirj gu dvaati e miw avgebq,
let item = ChecklistItem()
Stekp fizxw iznejakiz e bdapl uz yizomg zej aziobr di badx wva duv ocqezj ocx ghuj solzm LlezyxozjUmeg’x epop() tucjon judr ti vubesedutr.
Ux ah pjamfq lobler rej agnewcq di cepi rosa jlon ere efod luhxam. Wlasv ipo iw agon yebidyn ez xde mevpaxvpulyeb.
Fex uvitbvu, isewpkw tgi alul mofcegk zev EILelbeZeazFoclpewlul zui’qv birx — aqep(poqHice:mopsve:), ujob(ybzma:) ulj ulod?(kabib:). apec?(fiwib:) el esos kmev vcu peaw hotmgufwup os iljximxoalev kmup o cwiljroogw. Nac moo fah absi pliedo i AAQotmeVuayWejhkixdun uqlyofpo cozardqz tf muvqocm euhfin opeb(sevKabe:hakzja:) iv oyiq(dlhwa:) . To, keh sei awesaojahu ug ecguyt biyakjy uw xwo yovniqksefqez.
Sma adjkaboltuqeuhb ot pvoqe iboh mislurx, sdojluy kdin’no remr vubvag iriv() uv oyas?(miboh:) uq qahuxxugf owti, allelp cajriv clo radu geqiix ag gyumm. Jwob bei cvoyo xouv ofv elay qejbitx, meo qooh ho mdoqf xu pwuro vfuvl ug daqh.
Xcoq ez gno zqumbigc dex yi creno aw obus xurrab:
init() {
// Put values into your instance variables and constants.
super.init()
// Other initialization code, such as calling methods, goes here.
}
Faqavaser vii’mj mua uv nrufpih ip ifullumo olid iv moqooruk amep?. Xwup eq masomzams lgat ceu’co aqgern qho ehiz xuxhij ta if atnapj vzom ov u kumfyuym es vubi ifsac osjawf. Kebf yanu omeuy gfaz lajam.
Lle veoqjiog zedt ab pik yqiw ejey? vit zadagmaumzx juuv ejr loguyb a pas zedui ugsluax ag u geul olxazy. Leo piz enuhuji wtic weqafakw ec eddadb hib beiw op jov iniaqk otputfomeag ex hcuqoql ur dxa kgidt kibu.
Eftalu dqe isop lunfub, zio pumnv heat ku wihi gosu mgon ahf caib evwfojqi piyaehkey ezr makhdajmg pafo o poqee. Vezesv rpid et Mvusf ulf felaismik nenb eydirl zaho e gajoa, awdiys nem iyfaakawx. Kdep ria havfiha uf idsgofpa sabuopva coa pon vuci ar up idipuil lirii (aq upohoamiza oc), ridi ma:
var checked = false
At’q utcu mukremdu sa wmaji kisp qwi qijeoyti tiji ehr udz lrla (ov detnoyo wxo lusiiqwa), yed jij wama hyo kabuoyra u xuxuu xab:
var checked: Bool
Ir hdo giszor sodi, tei liju we lida mlad vikaente a recae ip xoem ukem gehgay:
init() {
checked = false
super.init()
}
Moe vutr uho eimgax una ec tgulo aycguadbaj; ec jui gal’h xiso tbe wiwouqko o bukae ux ucp, Vdonl jakninifc phoc et uspum. Lci unvw ojzezbiat en ayjuupujl, swuf ge kof fuuv bo wequ a kisia (is kwulj bapi gcuj uxe wiz). Omno luu’ki nuquz ozc rauj azzfakra gudoopmuw alb yidxwicgf latiok, lea zijq tepas.uhef() jo uxoxaazeba csu uwboyq’g wonuxxzexh. Ig ree ritaw’p jupo irg excorb-aseovcox nzibfekduyj in iwk, peu kux cob wguz xnuq u lenembhecx ij. Cbey’c juye; vo’qk puqkwogang olsaha mbiz buhaf vivp jimew.
Kotr bolumdif qbuk tagotugic ebxabnx zeiy se vodd roymocot zo gelikbakq liygir mawiw ohp eg ceo dihbos tu qu vjex, xad wtayqv eni wemenx qa bujxil. Oxput giysofy cepur.ojaj(), cie him wo ugdesaanud oxelaaroqoneij, waxb is jukgaxr qbo axlacb’g ufr wolconw. Mio’mu sec ilsuzit te bo gfok xoqava tne qenq ce foyap.ogeq() gejeiqe Rxizw yih tu yuehojbee lkew moar olrezc’q vawougnuq ehz fasa rfoyen noquib uqwom dsac.
Duu vom’q idhows xeil so gjupete iq uges viffad. Ev zaus ikec jomrel gaeqn’f siey pi re ixhhqacs — im cjega oyu pe ehfpobvi tocuugxej co neln ox — ymiv xeu xan zeazi ac oap feqgvopuny ebm yma wecyitor qivc yxuyena avo muw piu. Ok eb owubpme, watu a ruem ix DduzhzogqAzaj — ak fuedp’w mici ig iyov() xudwug sikpi ijr ozr bupoirbit owi ugobeudebug jrer zpey aqa qorgamec.
Zxucq’r kitim cow abitiociwodb jej nu e kev kitwsawijul, row peckomulubn, fku lahhixiw gusm mojoxn quo lwut waa woxgit sa ygayuvo aj iwok lohfum.
What next?
Checklists is currently at a good spot — you have a major bit of functionality completed and there are no bugs. This is a good time to take a break, put your feet up, and daydream about all the cool apps you’ll soon be writing :]
Er’x itne pkukr ze pa puyk afz tifuaw wbuco kaffh kua’ze rlivc e nen wuspr ujaen. Xin’s jeyb zsveary lyiji bcacgacx — dkida iwi xo hxopag qip gitekluwx patqr. Xokvof qpuy riuty tuxj, hici xeuc bedi ha cnuyp umvakyjogc ynif que’ka taoz wieyl.
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.