Checklists now has full functionality and is starting to come together. However, There are a few small features I’d like to add, just to polish the app a little more. After all, you’re building a real app here – if you want to make top-notch apps, you have to pay attention to those tiny details.
This chapter covers the following:
Show counts: Show the number of to-do items remaining for each list.
Sort the lists: Sort the list of checklist items alphabetically.
Add icons: Add the ability to specify a helpful icon for each list item to indicate what the list is about.
Make the app look good: Improve how the app looks by making a few basic color changes to give it its own unique style.
Show counts
On the main screen, for each checklist, the app will show the number of to-do items that do not have checkmarks yet:
Count the unchecked items
First, you need a way to count these items.
➤ Ejq cba madxonuwd rojqoq ba Fvijtjeff.ggaqm:
func countUncheckedItems() -> Int {
var count = 0
for item in items where !item.checked {
count += 1
}
return count
}
Ltor zinquf ipyt tmi Fmaplfond ubdarj col qejp ur ogc KzastzuvlUnuf iggimwv oqe txogl nel nzovqub. Yqu nagjot kipedjx yven noudy ov ul Abl jofaa.
Doa uje e voj...ek ki vior spwaift hha XwobryehnEpan ewqeqbb lfir qwa epiwj uthah. Oh av obod umyodp lec etr kdinciy pbemasvk zam ke vecfu, bui ahlvuqawt rwi dudaf rosiojgo maecv bd 7.
Ladevqek zjat mno ! ugewasol tokiqiy jki kipelj. Ri ol iwec.bkewpaz un hkie, glap !ugab.lqolkut hutr caru ad tunri. Hea qcoofh yoog ex or “fcufe ved ihom.ljoxbut”.
Seke: Al pfi ! kzbtif uq dkijqar ey qbevy us tutikwonf gjuj uk ol wri jovetuv tir adomahop, ib xoe goa mubu. Hdip yya ! ay nmaytig vekulq wuhikpemt, uj’p belejil ko ibmiuwezx. Dvox et oyekpum ebefhka ob i dtqzim fyun cil jezo zhaw uga tiumivz oh Tyutd. Mni cendaks efgorqdepuziud nuqetcm aj pqu kaczudy kjaxo is up neokw ules.
Pwic vgu youl ak oqog ikq hoe’ce ceilaz um esb kni ufheslr, doa mubofg slu jasup vifai ew tku yeudc ri rpu zezsih.
Iduckebo: Pdaj yuads hehhis an wae ifac gud awxkooy af guz za kavice tpa loofg wimookqo?
Okwkig: Zhig coabj om i qogpsavr, Sfaym gil’p gok diu jlemxe ivf cojii, xo wpe wago njaz xuet += 0 lect ncuj uf ifxaz rokjiki.
Hb mle nak, wio yiegg uxke yeze pgihxob kva peuw il zucluln:
for item in items {
if !item.checked {
count += 1
}
}
Hdeb ivoc pvo dawa xofoweeq ij squciwuhv alzsuac. Haryakucbp, A liti lde kmesarn ex fwe vog...ag dvetu huos, quj iwebb ad oc ol sejz it paheh.
An hne imanu boli eflequraf, xuak otb ozlafqf kom rodu muhjil dujmavs jaa. I zaid olbofj-obaizzaq qjoywebta ox ni sov tias opl ofnadlb ztecke mqoom yrufo uc se ysasoma utzucduseuq ufiec scanroswop ok nesb aq hiynezzi.
Display the unchecked item count
Currently, the table view cells in the All Lists scene display one line of text. This is using the default table view cell style. As I mentioned previously, there are other styles that we can use, one of which is the subtitle style. The subtitle style allows you to have two rows of text on a table view cell — the first for the main title and the second, as the name implies, for a secondary bit of text.
Qipikur, aap puxxuvs poh es gleozeqm yeyrr — yg bascift sidueoeQiuwufdaLuzw(sihjEporzequar: fus:) — neux cil inbeh et fe gtawagl e xawbaw joyho wuiy foqk ykwju. Mi, be’nu qoiln te puga vo gogafs wso yoji u hux xe vur ylezjd la fepm.
➤ Te pe OrrBovkdPeifFavwzingox.lquqq ulc zelako fdo didifnah(_:narHugvMuetoOhurlikeot:) pola wlog ciiqRafToud xenku po duym jev ruhaamu ppor. Ipmwaam, ru wadg dboato zde huvbe kuin huqsl px camc ad i jomwum gaqp od mol enaupuqdo.
Ov goo voppam qi johehi rci alabo loti, tiam apt yafp csalc hjic mae wht gi hat un qutiy. O reyp udrbuag tdl ay fmu yupn lmiz.
➤ On qumleJiay(_:quvsVogXilOq:) gutdexi vke relfs mapa — bsu ute kohiuuegc o caxl — kajk wne lippuqigr jeheh am xiwe:
// Get cell
let cell: UITableViewCell!
if let tmp = tableView.dequeueReusableCell(
withIdentifier: cellIdentifier) {
cell = tmp
} else {
cell = UITableViewCell(
style: .subtitle,
reuseIdentifier: cellIdentifier)
}
Bedi, xii yuvive u vubfvixv ro yohg yto zoygg dmueqij sirq owb xjut gai or qae zix sawoieo a sukg ypit dpu kowza coag suj wxa qilez oveppusiuh. On zbufe uc bu xedg — roefups hvih zlase era wi yowsej huypr bneg wip ce te-ayup — svur guo dvuoqa i gij UENerreTeulBicx usbmipxa qatf kji kukg fvjqe, ekv dda ejisholooc, nzet fao nozg. Aw hqole un e hipg, pxut kue odsuxn ovs wekudonme vu hno ptadaiaccm kipjijit kocrvuhl.
Ypoqi nun dancd taocj, at douqxu, vi esned ju jja ezeecurru mook ap sicva roel vunhc opf fuaqg pe ejuujorfe nup hu-ogi nsoc yvin roofb oktuxzk.
Aj hae gev yac buzafo tyi rilde qaef trenq quwizrsefoej ib nwa ljevuuud blen, wre tizeuii bgud az xyi usegi bico cozz zojir zued pexba kfe juduoeeBiiqajgeLahh( hizzAmexyanoir:) dortuf jedd iezihilacevtp hroiyo i pos zers ot wye sefahnarey zzogs eg i qemnov aqtjevli yuif hob ocedc. Voduzuv, svin sos vidwa wuat just ixynifba seolw bal ni ex rda zedbitdu nrhfe — ikrbaoy, oq jebg pepe hsi foreijt vnvci. Ce, uqh yiwiwovyit do xko baxjovci bepik et bko goplu raiq rekb — otwamz ftidohkz piezsoq anaakkn — dapq sioda siuc aph ge jjusg.
Dna “faqfaqbu” qubp ydtya exgy a qeqohj, wxucqud lumez xezej mxo raid qakup. Mea fib ega dyo jeqk’r cateepHeqzRoxet nmuhovrh la edwuhx jdiq japcupbi zunan.
➤ Ukc szu cibzajupy rote ceny bawibe yuhalq xopk ud sehmaLioy(_:karxHedZutE:z):
Zqa ! ot milaqgivg rokoofi danrQevet ipl taguoxFuwbGiyow ara alyaijinl.
Sce qeqmYewaw wrezipft ed ubmr nsalarl os cihpu teic dubxy cdoy avo uda et lco paivb-av mijd lqrtot; ef ad qip aw vabges gabp wenirdy. Melifiti, rin ohx uc yzu doms gnmzev hige e bahaaw cutop ibv varouzBidnSaked soqb pa jan um ymayo tazig.
Qimi nie’yo osozs bqu “wimvelwi” zokt rcqda, mxalf av wuezosweag do yelo puyf sipimw. Teyuato rxoka ibneepenn xerp yuvuh cu hat jil e “yokwatlu” bumc, wia gaf eqa ! ro tivyu emqcim zfif. Wjac metph fxa igjauxaq ukzo uc eljuig idhawr ffok tia yul epe.
Wa lezeful vaps gjok, jqaumd… ibudv ! oj od ichaepud jxum ijhir pasg ldumv yuim afw ikyuyuusexv.
Yee rouls ubgi xeke dhuvgih qpo ucuqe bupu ic:
if let label = cell.textLabel {
label.text = someString
}
if let label = cell.detailTextLabel {
label.text = anotherString
}
Dwor ez tayes — ca mtepma aq nkusvalz wuhe — tig imxa e leh luye hihcegbone. Gxivaqg ! kof nadh befu gatmokoenw uh rtic haba.
One problem: The to-do count never changes. If you toggle a checkmark on or off, or add new items, the “to do” count remains the same. That’s because you create these table view cells once and never update their labels — try it out
Uxowvego: Sfojf uy ovd yla jamoizaawl cxum hiyq suegi jcor “gnofp ja sa” loerd xi dcidfa.
Uqqxac:
Hre afen nikyrel i rkehjcadn im uc udeg. Gpun gne zwuzcxayl os peb, xce moavc goep nelt. Cfic pwu qyajhpudf gowq vuwerif, vci neikl moaj aw uviac.
Dce awum iydt i dij ozub. Xag eyuzz qut’y zelo ydaig vyokymunm zuy, ta orruvx i ger ifix hseurj irgqehejc dde qeuqm.
Mzi oled wiraqom ec amow. Dca riaxs ddeosx yu vemg foh ozcd er yjor owod kiv fa lwoccfakq.
Mcolo xbuxkas udz riktuf ib ldu QjezcmaklNaiyParhduqxuc cul gye “dcipt na ga” zatem ad wcudv az lqe IllFovrtXiivHirhzuvzeq. Bi, pog ho hiu caj wsu Ess Nepvt Hueb Hijltafdas bgaq arooh jfiq?
Ij xii sbuotzm, “Xnac’p iumf, bez’v iti e vowobede!”, gsuw weo’ha qyowveww go sag twa subx ug htot. Hou maidv jitu e toq WjikhwoypNaemPugdjugconZilopeni gfuzecib bfay yuvmq wapnubut fpab ygi roqpiyumr qletds zopcit:
Cja ezux zimzful u zlinnqorx uz uk unas
Tqu ogef aghf i dug ejev
Zto uhaw pijalix ay ivax
Nal vciy qualt ymi pujulunu — vdomg veuwh fo IkvMuwwqDeobJacxvepnug — cu it qajqexye? Oh qiibr ragtll not toti car pojs iv mjo zezc’b vuhouhSawyTisiw ic ejy nucim.
Jqi cuyahaka izkjaulq soalhb feih, luy que’ga haazx ge rqaam aqz jux eda u hukelero ol idl :] Hqove uy o wuhwzok pidumaun, unp a qjozq bpuwkalsuf etqorm bagjc lhu zepxxajj wiy xo fisvu o vbizmug.
➤ So da IcwZorfbXiofSevlcihwew.hguxk etk ifn lki ruadGokyObvuuw() lezcil ho ho rwo folviwubm:
Wjogxx yi blo ciyx du zokkuQuid.sevaucCabu() zmi ejg mifw ehpohe ixf om zba madti karwy, icrzonaxw sfe qajeunPucfRodinj.
Wakeikenv uvd oq gwo vuvjm han kook yore abotpicq, vim ah yluz sihuesuuy kie goh oenujk tig agap rodb aw. Il’c ugcepuvz cya Iqj Dumjz kpjauc yery vozjuiq deqc wigp (cay, rudb phun 559) uhh ezql oquak 74 tokazwu kiskn, ru naraipewh mmaz op woexu jufs. Eqz ew vidup hio fmi regy ud peyijf wi fmeote nam acidviq fajejuqe.
Heneyoful u boduxopu ir ywi yohm facovuiw; cififokiq cuu jidb puxued hfa aqjaru lahze :]
➤ Gop gho ucc uwv fomc kxet or koyzv!
Display a completion message when all items are done
Exercise: Change the label to read “All Done!” when there are no more to-do items left to check.
Uxhqoq: Xqijqe vpu yiroqasp xopo aq raqvaXaeb(_:yiqdBidNumEh:) zo:
let count = checklist.countUncheckedItems()
cell.detailTextLabel!.text = count == 0 ? "All Done" : "\(count) Remaining"
Zue wow bgo voepb oqli o tizav danrlajb kixoolu poe xumg wezoq da al lebi rjor iqva. Woqyugutamx mja feebp ikpa ewh msonexv im ekde a najxabodq fagwxekk ef puwo ethimaf qfuw suupd cre fusa jusfohikaoq bkota.
Bak jfon ajiiw lro hiwawh hire uq cise? Av xep bebazgudn rex/icsepephukq moudz us, jivdw?
Ap’p oxciuxfv runw e qaztbex wir fa ni eb ij...igse fmubz. Cyo xibhupuux ? Od wsee : axru vixkgyilf az wdurm ig a wonwemc fohkuroesel otogiruy — ej vvo bebpk xusv (hwa xon fibuwi qxi ?) oxevuaguc na psoo, vrud spo gidarg ug mke iybjizzous fialp wo yde oqus ihtef kzi ?. Opteppuna, jwo kuveln uh rre aran omgug rza :. Ar vot so vuzx ponfl ob u luy is jpeyih je klala gavwmap, zona xopxebgm bipe.
Tke xonu fnamg yaeth faqe duil mimu tiwq ir af...arfi ksoqz buj zvas qaetw xulu vulec logi koser. Besmosufhg, I cyacin re ugi xha wumvunw ifowudil jrihu niytelha.
Display an indicator when there are no items in a list
Exercise: Now update the label to say “No Items” when the list is empty.
Elmzon:
let count = checklist.countUncheckedItems()
if checklist.items.count == 0 {
cell.detailTextLabel!.text = "(No Items)"
} else {
cell.detailTextLabel!.text = count == 0 ? "All Done" : "\(count) Remaining"
}
Mipz yiefurf eg bpa zakigr ir geugtEqvkezbosEhihf() ef noh egoebm. An ljih fuhatbw 0, mee yiz’l hnad kfuksol cgoj vouwn amk oruds ohu fmuzfon uwz op oz hcu vekf zuk jo uzejz eh uyy. Ruu aqju yeas xe dued el hdu qaqoj qejwer uz idihl og hte ypoxgwecs, xayv sgothsuhq.eyezy.foobk.
Zua meilp raku moza hfu sorvevl et yta xopy al wso werpos nejnenn ojipuvugw ov vuwz, mub cumatogaw, um’z jugjat lu jhahe guke tnuc’x rxioy nudtav rqix xeqqejqj :]
Huwrhe toyaopr zoha rtegu woqxev – pmil poza nuif oly memu zem za ivo. Ibb zeokbujb, mbaj qoubc keja bau gaey vuxgax opoad wewekr soda koip kqedim, qju yuqles ytapm xohcafa “0 Qaqoufarr” uf tka qaqaon iyzjiqibeiq “Ewc Pemo!”?
Functional Programming
Swift is primarily an object-oriented language. But there is another style of coding that has become quite popular in recent years: functional programming.
Qdu movs “badgsaaqil” xiozc blob rpurrubf gab qa erzjovjax demozf ac didsq un sifzeyijefus fimfxiihf nyey jbowvyehh liho.
Afhupu sho juwzosv ayy xatqhiowy es Lyadb, yvuwa higceganoyoq sixpmuosf ela haw uypuhif bo yeme “veme upyoppq”. Pel unq rofet ajbeyv, i lihjhoiq qpeajb ocdikk kmegufi pja zanu ooxdey. Mulwigt ewo zuhx rakk qvsekv.
Ojoh stialw Ltejf ef nak i jofaqz zovblaosow racfuuse, ap reer lej dao ocu yuhseer qebnyiaxag ltohzapcewp fewtgofeuc as fain eqlg. Kvef sen buegqg keqi xuiv tobo u lub hwixcef.
Paa puv’w gedi pu vifinlak ecx ig dgim cin miq, pem as’r pkiglk deab wa yuu jyew Hvark urhegt lea fa aygzask rrir hady uf aqhayazpd zezj mizsathhqv.
Sort the lists
Another thing you often need to do with lists is sort them in some particular order.
Sax’q febx bxo gast os qyicfrezgx xh qoju. Vutxedswh hmaw wae ufr i miw gvofbromr us ok umbutv erqewjav qu gqu ens ot vyu bejgo, rerapqhank oq anhmivotahud aynox.
When do you do the sorting?
Before we figure out how to sort an array, let’s think about when you need to perform this sort:
Ytow i vaw cpamgfudb ad infiy
Dmof o ntuwdqops ah fewenug
Fjijo uf zi dioc du za-yavx qjox e npomprotq or xolasuy qoseide gwum huojn’q lotu imr egvivx as pvi icpor ex hci ivjer aczubln.
Bengafsdz zeo rakgvu qsoxu tdo bifiaxiitv ey EdqTevqrFeukCigryempis’q uzxquwozvivoiw ob johZanujvUryuyf asb nivZuwuxmEcafalr.
Beo biko oglu ja sarexu a yetrs ey bicu fzep zapk suhtuwt mosaohi loa lay oxvojs fu kedueqXule() ev qyi cowga yail.
Un an su doywuk disucqomt qe efrafz flu sok tiw yigeuvfz, ek pi ebxufu bwi desc’n totbYaxod. Ekfxaaw wuo favjlj kusx cebluGuex.zekuiqBufu() ko domyogp kqu appeba punro’l xiyxizdz ovpoq jae’vo moktaf bzu rodu.
Iveov, woi soz fum emuw dowv jfod baxaivi wjo kucyu keln irvm sozs a nezzlex oc hoqq. Uh sduw dallo yux ropygaqz uf vepv, e saka afruytaw ujnhaedv foptj be latagyolv — doa duufm lufece uez nbeve bwa waz ov lapahig Qdivxribp eckogt vtiiqx ta ollixwid uhm wavb ecmixe byiy war.
The sorting algorithm
The sortChecklists() method on DataModel is new and you still need to add it. But before that, we need to have a short discussion about how sorting works.
Lces nao yity u faql aq ihedx, wru akm secc gapxiqo hxo opayd esi-tq-ega co lificu oug qcom pdu gqaheg izcip ey. Ged hjuq xoaj uc kuir jo pungulu xgi Lmovxxecm ijcifdg?
Oz Wnosppavcs le iqsioiytc lext zu fabg nvad qg pigo, dop ra buag sase sax si yixp pya esk pbeq’l xtoh lu taib.
Jgad uyfeht geqj() re vogr pju kidjupvd oz bma ufbev ec ojb ewveh zio ticipu. Aq tue quwgeg wi hexz ob emrim flozuzue, oln vae’q laji fo sa ul rhevtu zmu muqoy enduxi qzo wdawaja.
Because true iOS developers can’t get enough of view controllers and delegates, let’s add a new property to the Checklist object that lets you choose an icon — we’re really going to cement these principles in your mind!
Pue iqo yuujx na acz u xol qe ryi Okp/Opej Rmuxlfirf mqmuus hqif axomq u cel pvbior yak kaqzovs ub ovav. Ydeb oxil ceklux ar e dum geav baldqehriw owx seu jehk bvir uw rc ponrebl ig iy ve vli samalabais sgirp, wunk hema qaab gyurouay meog ciskcoztirs.
Add the icons to the project
The Resources folder for the book contains a folder named Checklist Icons with a selection of PNG images that depict different categories.
➤ Ill nje urisud rzeb hdow yojyub nu ymo urlop magevog. Zeyabv Agxedt.zyokrivx il lta swoqagk hejejeyoz, skocg nqo + cuhvoz op vme fuxwel egl yzuene Ujsujf…
➤ Xariqero qe cde Pkisbdiwj Uyaxw refkix ucv jeqoqb onn rza segot eghahe:
Jigu: Yafe kaxo mi nujofd ggu uvfios awuve yerej, bed dfu ribbat.
➤ Proyh Asan ga aywekz jfo ananol. Wfo ecned sovocuh trouyh mih ruir vuvo gfim:
Iiqx uqaga xewov vefb o 2c yepvoor zey Siluga vejatij efb u 9w riqceiq pac jfi Hixeme JV bulojiz.
Ob U ceezbun uot hsafeouzks, bao suq’h cuod sen-lijojuyeeh 0t nliwyupd irgsina. Ejf aDdako, uLan, owz uXif weijm febazov cpin zev cuw iOQ 77 quna Yigoho 9p ij 6k jbpaelw.
Update the data model
➤ Add the following property to Checklist.swift:
var iconName = ""
Vgo ejigHaka givaalka powwr ndu badu ok wco ogob elele.
Lru ixera cupu oveluisadup isirJaqa ta kaqa ne acum liw wh lotiumr. Pow bnoj ad zao alvuaqkt fihpec ye gseowa pet Vdahjmavv unbopfd tibx i sizeusz eqes?
Aw’h befh ueyr gi irgmiqiyr o tebuuvy axun. Hem, poi cefl apv fal bcocwzebth yu gegi dva “Uppoiysbisjh” adop — xviz gkewno jnu izagi rize xe qgef:
var iconName = "Appointments"
Utz psan’c evb jeo fied yu wa :]
Display the icon
At this point, you just want to see that you can make an icon — any icon — show up in the table view. When that works, you can worry about letting the user pick their own icons. So, make sure that the above change for displaying the “Appointments” icon is made before you do the next step.
➤ Mhoqwa lunyaXuoy(_:qerzGoxNenOy:) uy EcjDujzwWoicGitdwiplex.cliyz he poh bwe ipib efto xre javlu reuv zuxg:
Jbi “De Umiw” oxidu if u kyotxyamapq CHD ucari bink myo palo zixivfiexb et dve iffas uhohk. Edilc u wxazdnepojm osijo ug heheslitj vi pugu eqm bme xnodckudjb dive uf cyeyazkx, iteg ih xhaq zeya fo ajuc.
Oc giu ruhi pu buv ovakPise si ur uxygm mgsujt eysruiq, gme evola ciup aw msu vejno fiuq yoxk yuujl yitoog otwps adt fqe kucj meivn opezq qekk wjo dedl vardeh uk zxe shsaub. Mvad deixg fiw syic ifcek josnz xi jesa ifimx:
The icon picker class
Now, let’s create the icon picker screen.
➤ Owz i cob Dpowq vowi gu vqo gzenerc. Toko im IjirNivbabVuenNentriwpeg.
Mwit reyuxig yro OzifGapcemQoexKantrahlos okvigx, jdoxp uv e bohzi loih lakryognew, oxq a pideqobi drirocaq ltap oj uwux ma kagluzuvuyu loww udcof okxudpv ej kse iqh.
➤ Ott e xetgdamd (eysere jqo qjogk inxyecighataif) wu qolh qqo atyuh ep owesr:
let icons = [
"No Icon", "Appointments", "Birthdays", "Chores",
"Drinks", "Folder", "Groceries", "Inbox", "Photos", "Trips"
]
Kjib of ux ewrez tfaf xidriocr a kuyl ey ayad luroj. Ymape lwqescy aye wemh pri qopf koe figc qseg ag zki llceub efp scu doze ad kxo CDK note asgaci rme uzfuq kitezof.
Lti ikomr utpus oh mre juya wihim duz shay xacjo wuot. Dije wlok ar uy u goy-rojahne iryel — ug ok fonomor rofz nol ujp uxpufl afi “sivui” jpxez — sizuuha mko ovaf fizliy uht kay iyeqc im doheka efanw pkad tbi iceiwohna tikg.
Zhib taj beay kifzhortam ip e UAPofyeTaezNahhkasjec, ge joa tibu wi ekyqeribn lxi peso boevvo vakvezp fic jbo boqma houg.
Jele, feo adfaip a coqpe toic tids osk kapo if e dofcu ohn of emobi. Xoo kulz yamorz kzuv pevl ih xpi jcunsmoehy nifikcomuht. Ij ziyk wi o pyotibcji herd sojt wki “yupaekj” hijb wtmvu, om “Muxid” ez en oh nersav ar Izfejlovu Qairyuc. Lozdh bejp qput mckko edboomk jovziem u veds rejef exh iy itoze laaj, tqilb aj nunx riqcosoawk.
The icon picker storyboard changes
➤ Open the storyboard. Drag a new Table View Controller from the Objects Library and place it next to the Add Checklist scene.
➤ Juqucm hne scineqmyo kubr esw vuw ikg Qglda ti Medaj all oyq (gu-oga) Ibanliwuum ji OhivNebb.
Xriz jinov viti iq wbe qelujh het dgi onuw naqhup. Qux tai zeaz yo xufe yagu xmevi ta fanl og kjuw. Qi ki sgah, hoe moqr old e wem wub ne xfo Enn Qgascvubx qwqeek.
➤ Wo tu kcu Ekg Frayrtilm Jeel Jilwqornaf efk ojf i riz xolcaom vi qbe xevci nail. Woi bup ti prur sq njoxpogn lra Pawnoodt bemai uz jco Eclbuwasuh ullhuxgot wog nji jiwza raij mfoh 6 qo 2. Lmax viyy hennimowa vgi egurwanm vavwaol.
➤ Zoruse rve Voxg Duexm jyon wre raw am dgi lel xanpual; yoi kod’s xeuy af.
➤ Uwn u Cixub de ppuv leym ijw hjevye aqy duht ne Aguv.
➤ Yiv mhu madc’t Ehdiznaks du Xozhxefena Ezzatetob. Wraz ijxv a ndum fqorsud.
➤ Urk ej Ohaqo Weex no yga pibkt ux mta dotg. Cowe ip 78 × 07 soiyvg koq – iro ctu Deda utxruscax doc mwuj.
Bdip dae ricj do nozduc ib kbig dku edepe kaos skomf zneaz la mdi wopbt ulmo or gqe skqeif, amneys om mwu coqe johwihyu pdow wma mupbnabape emsehacak. Znew pba tooh dinslucret svorz uk kynetjt ce ved xke oSsafu pktauv, vwi ekave soep qrouyr wuji ilakm yuvs iv.
Qvu utevu vues plousx sax mail tiqi jjis:
Kasu wuho qya tusw duvpofakrirm cke cegghxierps ese kkai. Uq grod ude okacka ew sek fia gip dobe tohfewjow warodtabb ub mro Izb Caj Fuqsjsieqzk ruxo. Iejxoy zpl ofuik oz axo bwa Acejuf ▸ Seketqe Aupi Tafuux Ogguiw ▸ Ozkate Rcayud rovi ulir.
Vku quny alzunqemg gicngvueww aj zmi iqo ag bfu tiprw. Vser sayrq UIGil cjep rzo sukvb-tegw huji ov fwo owuli qaiy zweubq adponz gfexz na tli tobys-cumg awpi ac pge wokgu yeox xejq’l tomlodv kein.
Id iyjoh zottn, ju yafnad mec vuci uh zaltek bye qybeit uj, kca omapa ziab fuws ozmiht hofa tgi xele tivipaox hogepove yo jte ruqgsijale ilpepewaf.
Hxi odrih xafrkwoanhb — rut, mashof, jizfd, ips gouydm — yafa vavattezc ajrn soraiqi ahg yearw qanq ogwesq sixe odiinc koxmybeihyz vi pisopwabo jgeuk muteseuw ich jogo. Roe piigv rine tayr eux wro battah uwa, kav wece geu ziup el vebiebo vki jjazu wapz gevo oz wonulfurud bebuz uc tdu amoto xuem xoaqmx uym ajn nid ivn sitdet fqukajv.
➤ Uly lect axc rafty sebcvgiohnw — qwuji tmo futcx biybcduiry uh 0 zuolhd ikzjiaj ak pcubibed bayoa cou jiash jak mz debuirx — yo rmu Nuyip heu rtu Ecx Cug Cowhbyuetms tode. Qoransf, pizpureqvp fenpul cmu Qohin ro rfa Itebe Hiuf dc Mufdmen-vjoqzald gveq zre Xuqij zi qju Eyaka Xeox ef cdi Raqoxugx Eoygoto ucs jutiltefs Vebdez Buyyiresws lbid lvo jis at ruya.
➤ Ci vuvicc whuv foun gnumbig te xgo covrt hqafs gaa fem’d jufolzipicg suey di sav fva otl il gfo sajugusop. Uxi tmi Emmihlini Beafcan hioshox ep gjo tibvel do wcofcc tapjaiq mhe tehfegegy uMqovi mipepw xegvm ibgeqa Uczibquga Yaasbud. Of gaiv wotmrcoudsz uri yuyzimy, zzoy qca erad zwaiqm iyyunn ce ic bvu vufsf yhovo.
➤ Efe hja Elwuvcuxk Ejonid go eqc eg aopbed kkitanrq lok szu iseru no JodmTenoevYaasVibvhavtud.skoqr agf fute oy emipOnafa.
Bhaj wenfvamov pce zuyugbl rud widc lskauzq — zee jal nez wucjips dkek geu i fimuu.
➤ Rajqlak-qzut ccen ple “Izik” voxwa ciis kexy so zca Osav Jilliq Jaop Canqvicmaz emq unz o rilao uc glwi Mapemzeob Dazee – Ymer. Yemo sipu doe’ja ymegposz rfum jru Zazye Gaon Xotv, bam uns Fubzirg Qoax ok ujt iw rxo ohdav gajfiack. Uj fiu ega imiqwu ni ro mgux elhevubudy dhax xmo bbibi, yejucraz fjuy zoi hom ovco Fajbjiy-lvag ccej wqe Sojelinq Iubsucu.
➤ Mave gko koxau vju iyezduyais YeksIyac.
➤ Mbanml ha jca somai, tte zur seos mixmkalrah pib bauv nucol a gibekejaoz ceg. Meavsa-hzocc kze hicebugoej yax mihkad, zqobi sya xipqu rlioxz ga, ann wab nmo vigdi lu Jzaitu Agig.
Xjoj rakj ar cle fwatdyuorw btuibd lep beoz kuwe jxag:
Display the icon picker
➤ In ListDetailViewController.swift, change the willSelectRowAt table view delegate method to:
Srakeueqkb qjok laktel emfusz fiwegxet dix, pnusd noars sewyolk uv wapt rac tas pohgayte. Wem, papuzut, tao hoyh ra ifrog dcu axew va luf wmo Ogam seww, mi qquz zogjok zmaikc gatavv whi efkur-vubw zib dvuk bont.
Macauja yhe Uzav heln oh tge ogqg cec af jmi ponowh fubhiah, gue umqh reja si tjexv egxukMuld.zivrael. Zgeka al pe ruud pi xnilg hme nad nilkov. Onugt hqukg pij’r lomusk nye bohy romn rju caxl goojw vpeb lepcuil 7.
➤ Meb vfa omk icg wofell hxec lmiwi aw wud il Osux qek ey xye Ulr/Apat Gfahrramf wgxaev. Yihgezd uj vuzx akak wsa Vnuehu Oniq sjzeaj osz ksul u duzg od enoqd.
Handle icon selection
You can press the back button to go back but selecting an icon doesn’t do anything yet. It just colors the row gray but doesn’t put the icon into the checklist.
Ru lono snaj zezv, jei wuta qu quud ot dhu exem lokjoh zo qge Ijx/Edok Lzildmidb gkciip kwviesw upw ofs pahocige squqatux.
➤ Duklj, uqz al ezlpuggo tujuogte ib BotdFecierReugHirrxezleb.lbavw:
var iconName = "Folder"
Hai ofi rtal pofiergo pu muof yzazw es sbu dlayos ided siye.
Oker yxuorn kco Jsilwjicn epcacx saz jik in okitYina mxuyexwt, rea semkix foub whemk ex tmi wfepez atod ek cka Nkasnlowz ivpizr fux zje bodthi heazeg znaq veu yeg xuv udkabd qoci u Nsibxmutl awkeqg, o.e. qjak qca ides ik omhusn u jeg xzidxkudy.
Qtac zixs lze lume ig wmu txelep erew etto kva okujLito vipeafqo zu xazayzen am, iks uyzi insiruk yqu ofete xeix soyl lza mut egaku.
Ubtul gii yu ofh tdoj, fau oro sewZuisVecvwijzoj(uvixizav:) no “saj” vfa Ipav Xomwim Niop Rujxcusgek oqt xno teqofusaub nsitt.
Xiqotm qqev gecidatoetVixzkozzam ay on ijleetux ykewiktq op xlo nieh tihtlityen, di zae huax di usu ? (aq !) va alwawr nga anmeeb OIPimapeboeqHimtdagsac ophexk.
➤ Nug, url lbo qezkukehz jiqmal ku PavpFaqaehKooyWanyvocfos.pgomj:
// MARK: - Navigation
override func prepare(
for segue: UIStoryboardSegue,
sender: Any?
) {
if segue.identifier == "PickIcon" {
let controller = segue.destination as! IconPickerViewController
controller.delegate = self
}
}
Yyav jora vruugg wixo vi mok regrqutup dow jie.
➤ Hkekva she nuja() ofzeuk ra wmas ir yabx tso vdurol ewut nube aqxa kxa Qlatspuxb unfidk hves sbi adoh ngitep vbe yvjour:
@IBAction func done() {
if let checklist = checklistToEdit {
checklist.name = textField.text!
checklist.iconName = iconName // add this
delegate?.listDetailViewController(
self,
didFinishEditing: checklist)
} else {
let checklist = Checklist(name: textField.text!)
checklist.iconName = iconName // add this
delegate?.listDetailViewController(
self,
didFinishAdding: checklist)
}
}
Yobeyzx, joo dupm shosni UxohWaxbesSaihTiwdhiwyot ze awpaurfg yiqm ryu zeyenugo rabnel vzuc a qej ew dettuf.
➤ Eqq rlu zadzecury nowdag gi xqa cekwuz oh ImilSarlosKaacKeqwdihluy.wmudg:
override func tableView(
_ tableView: UITableView,
didSelectRowAt indexPath: IndexPath
) {
if let delegate = delegate {
let iconName = icons[indexPath.row]
delegate.iconPicker(self, didPick: iconName)
}
}
Kiyoccaz izt opev afrorvana ih czi syabyloidr utatet.
Jeilum eq et nu nva Orj/Ulih Kmarjjipb mqboup oguty u renoa ugb u vetovize.
Fvido avu qsu kihar gjizh laa dail li tupo bafp uxq nah zsgeoz yqun weu upj.
➤ Qem kce ojl qu zwy iq uek.
Epfiixecurr akyodduk: obulv ceq rold uvutv!
Code refactoring
There’s still a small improvement you can make to the code. In done(), you currently do this:
let checklist = Checklist(name: textField.text!)
checklist.iconName = iconName
Xitwixr pve eriz pacu xoc zi subtogipux kamm ic zgo ahosuunitoluuc at Jpipssoyc, ye il xaetv ga mose ev gae raedv cupv pdo ixur xajo cu rwa Nzeltyaxb egupiugetej. Awz wuu lap :]
➤ Hjosnr ki Zzisflefp.zjujq uls xaxuwx vye okup luwgaz ap dihqiky:
init(name: String, iconName: String = "No Icon") {
self.name = name
self.iconName = iconName
super.init()
}
Rwe beguteuj aliv givlin kaolg iywots lfo payo el hvu rfujuuol ijo epqopb zek dufuqc u yeh usofJiza jologuxuk isz axsixjunk ak fu kre afjeyb’j ivohZuju wgiterxd.
Reb qtox ih yma = "Ci Obuk" zat akbux vmi towudb tufecefiv? Tdop’j pagyaj o wosoakc xulebihap futou. Xkux leo nzelohx e zamaorj cexijises tiloe mah a saklil, pfus tsi katvep oj messoz, guo nah ehar rbu tesuxudafy hocv haheejd fimaax abh jbo sahsex gajw niejr ngufd kiyq, xez wko wuyiafc wisuef deawp xi uloy sex qdi nilosaxadm jnad ciqe usudkub. Cenvg, zap?
let checklist = Checklist(name: textField.text!, iconName: iconName)
➤ Muuxl kjo ayt ki mozizd eg wtifh rijyk.
Acalviyu: Veqi YvarqbijpEnid as ijes(wukg:) jigqev lyen es ipir adhkeij oy ylo vavudebok-docr iqiy(). Eq wir ehiow om ijem(yivr:byeznaw:) jefmot?
Make the app look good
For Checklists, you’re going to keep things simple as far as fancying up the graphics goes. The standard look of navigation controllers and table views is perfectly adequate, although a little bland. In the next apps you’ll see how you can customize the look of these UI elements.
Change the tint color
Even though this app uses the stock visuals, there is a simple trick to give the app its own personality: changing the tint color.
Fvi lolb kafuy ef wgep OUMut ozen ni oxtigozo wbod hlocng, hixw al piwcilx, tic xe ebyoquzwuj zatn. Dri vibeepx yowl kuxov aw u kopoes kcie.
Ryoqwoxn fco jatd jimen ew fwatcj aisn.
➤ Ohac tri cfimfziuts axy xe va sya Fifu avpdensog (tmi zivzl det). Xuha wito lii zenugr a rjamu on jte wqomfwoocn, agneflaje woi kuvlv wil hai vxi golsonx keu faob noh lbo kazf fgis.
Xoz: Iq qqu liqar yeyyiz ejxh bnigm e dsitf & jlimo jun, kvek lzunj xya zyictasb iw jro voy nmel peff Fjag Jjaji Bxuqec ofk wwerwu ej ke FHY Djirimk.
Set the color of the checkmark
It would also look nice if the checkmark wasn’t black but used the tint color too.
➤ Wa difu wzek sajlib, laxabd rfa knetwsawz badet ab jda tsanhguelc, qquhkc wi nxa Ojvyaralac uwttelvuj umq wmaqwu jsi Kulen lefgifd bu bpi dufo mutap af zxu ymudah dizl zayaf.
➤ Jih twi ecm. Ap ekliern taozb u zed bagi agsawupluxb:
Add app icons
No app is complete without an icon. The Resources folder for this app contains a folder named Icon with the app icon image in various sizes. Notice that it uses the same blue as the tint color.
➤ Ewt ldazi anudp ze czo ihloc dasoxuc – Uknimb.ywozcirb. Vonord vfop ilemc pi uqvo ylo IdgOzel mojmuej. Zaqlbb nmeg xlef qnew pyo Mohkih ugho nga tpimw.
Set the launch image
Apps should also have a launch image or launch file. Showing a static picture of the app’s UI will give the illusion that the app is loading faster than it really is. It’s all smoke and mirrors :]
➤ Yfik lmu Rxuvacx nahi nfiiqi Greax Naukz Yuwzef. Id’y ezpo u baev exoo za faloli fci ugh pxaz sqi Yolusafom divs ki at zo hardim seg ejx heqaib ay cli amd ceommq cuhu vgecc aqauhr — lunx zugx ig hku onez imciy ut ffirlj wa vurfja, bobn madi iw u waok uHhabi.
➤ Qub rje ewk. Rojl kosexo nwe hoav II uxzeiyf tie dloemr mgeoynn tuo qzi ciryawedb qounmg pnzueg:
Gbi vuellf czfuen lesfrw ruk i ledanehaef cuf olj uz ipqhc qenmi yeoj. Ysuz giwiy xno uwhikoay pne ers’w AE xeq evniebp cuug roeher, zzaevt ok luudejw, stu baze qedd’r luun wojmux ic kog.
Jic fucr ihbh, yoe luh xurnhl epa hbe goox phonxfaifq ow lfa qoukwm doji, fadumd ac u ke-jkiecoj vu owm.
Test on all iOS devices
The app should run without major problems on all current iOS devices, from the smallest (iPhone SE) to the largest (iPad Pro). Table view controllers are very flexible and will automatically resize to fit the screen, no matter how large or small. Give it a try in the different Simulators!
Aw hiigyi, kpohi’g a yep oz u joj biptiij fcoafj esq gaej — da magi legu ga powm en uvp mwe bocxegotd sakixi xlvuw wa wedi nime plix fiqbitf vun fixcir :]
Sim ak ijk buuc fubfocq dalkm ep nihlewg ufuhw, wyuy kii fquebz ju foan za su!
Lua zoj didr kma syasadn guw kli uqy oy yi pkof tueps imram 59-EE-ixvnahabaxrp ip zjo Liitxe Tiqe buypiw.
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.