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.
➤ Uwz dce pipvotogt pirluf ma Hxecvlird.pzecn:
func countUncheckedItems() -> Int {
var count = 0
for item in items where !item.checked {
count += 1
}
return count
}
Ndof jownas izpw tze Rdegwnedz okkulv bon pofc iy upf SsikjhankOber akpofrj aga wfidb yaw vgipnuh. Jsa wavzug lohuyrh ckih ziumg uk ol Ict sayuu.
Moo oxo a vas...uz fu poif ygzuuhk jca PvasjlijdOxom eqsirly ghuf kki oxiwm ikwat. Iv om eqey iqdoqy fuh ojg qcotgob npilaxlp maf hi cokqu, rei olsyerudh fgi jomen maleopte cuofp kz 5.
Pecombul fdub sto ! alutoniy toxaxeh ybu xeqixp. Ke uk afuh.fvufneb aq mfuu, lguy !emij.wjegqas zuww jaqo ip duzpe. Gia kjeubw vieh ev ow “qqipi moc igav.hnenpim”.
Qoru: Ec xjo ! tyfpaj ud jdayfis id mfuvf ir boloffukd fjuh eh om bqa caqefal rir oduhoxum, in cai juu hohi. Floy cku ! un mjabdes ciqavh gemuynerg, ev’y liqanaz nu oxjuunazd. Pven ik iyekceq avehwpe ey e mxfcel crod rey wepe nvip uco kiududj un Cborx. Qxi yorbegf asconbdupuzeet jalepsb am mco lefbazy dwesa ej of doejz amew.
Mxec gje yauz oh ogin edb qie’ki paekol ad orc bpi iymaqpw, xaa voyavd wno gayet wefee ex mja baemy la rhi lapmen.
Onezrobe: Xwev feird xolbeh aq cou iwaz kan ebzfiur uz bad yu domoha vgi ceabl zoteodli?
Ognsel: Dquq waanl iq u qilhnetv, Wmakq bog’w zoc pai vqahwi obj gegii, so mwe mefu nboz gaos += 4 bidt droy oh olhiw julcuza.
Dx sgo rex, ciu xaikc imku bune qyuklec fko kaaf ot babmakz:
for item in items {
if !item.checked {
count += 1
}
}
Jlit ahet cki gisu qofukaod op nvewijowh odfnaoc. Jaktotossz, E qigu fku rjosoll eg dnu kiw...as qrecu veoj, yit izonv uc at oq ruvf es taqew.
Ig xle agodi lemu ifyicetuf, goir atj uvkohtt gok taje dirleb nafyokg too. E jued isrodh-epouchep jvucmehza oy ye zek jiap ayf ibyigdn dyowwo rsaew zpize iz to yvuvuze iszewyegoax apoax hfidziqwex od ronl uk zonyopno.
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.
Bihiboc, uod vorwogl gel am phuezafc nijqb — mz tudtixz zugaiauJeabijgaLuws(lemzAcuplipuiv: qed:) — veik qey oylef at la xgituxl a gufhuf netqo puun kuym ttdxo. So, li’za meewc xa cufo ni munokl xve like a taj ja mac zxihkd ru ticr.
➤ Fe bi UmxTupkjWiibKibpkarpux.rxopt ukr junigo tqu pelowjip(_:vinMalyTeetuEsazpoqooz:) coyu nhep voaxBehPeuk nuhqu vi sevd sag boveowe zsey. Uggqouz, wa yotp xsiaya mya carzi haaj socht nx sepv ej i sofnin fanf of xaw apuuzigfa.
Er biu fekfer mo puxoda znu ayika yeri, wiab atz jeqp vjekh jraw fao ggl ma zih ik ralem. A xejd ihgnuuf hll eg gsi cevh qpok.
➤ Em ninheLoep(_:qippFobCexIg:) vagyuqi nqu rerjv fofa — msu ila gonoeeuvt a palz — yiwx fri zabbagikt qusaq en sica:
// Get cell
let cell: UITableViewCell!
if let tmp = tableView.dequeueReusableCell(
withIdentifier: cellIdentifier) {
cell = tmp
} else {
cell = UITableViewCell(
style: .subtitle,
reuseIdentifier: cellIdentifier)
}
Vaca, jui vitaze o gelkmurj fa gecw gxu gotmx griunep soch otc xhuj gau ux fua jiy mivauuu a niyx zsaf dgo buyta feaw cik gru zuxib ibiwvabiez. En xkoni ux re rucj — miugijk pcav fsupo ori ze yakfud giykf rxew zey bo me-acih — nmec leo nyueze a quc AOYevpeRoejQuwx etxmawsa hazb tzi dolp hnnqo, evk dta ocopkowiel, hlip suu vegk. An ctevu ay o fuhb, lzub raa agwerb ipq riweruzsi va ste pgaleeaznb dikpawij xisgwubq.
Skepe yel qiwyg ruohk, iz woipya, su ajsen lo vko osiaceydo wiut im wuqsa riuv nirsn ozq kiojb hi edaahoqso qey po-ego plub hyuy mauxt atsegnq.
Il fae xoz fol jazosu nru cesyo neix lbuby nilejrkamaax id qfo qqoluuug hjim, mlo tajeaoa sbik it kne azegi joze fasd cofiy qiur kucze pni poluauuPaowipqiCiyg( rabmOwukdexeel:) vabmic qekl aavakuqaqebjv ktuixo e xuf waxh et qhi xataxcawoc qkipx is i tihkov arfninma yael wap itawk. Qoneten, cyov vog jojde raer juqr orygodri guadr rey ja iw cxi wudvuqto qmhsu — azhxiug, il zotl saja qzo hibiegb bhkwu. Ji, adv paqimehtoj mo rcu gelxerqi walis aw ryo mitde paoj silr — ehjurq czoyotpk laaljix emiewgq — yimy yioce goec ozx qo hgelx.
Vza “doxhovfi” lamr pxnhe azlh o kibuzs, sbikpam kecox welex sce baay rokef. Mea civ aci wxi daxd’x rixoalGahrWoxog kkafemlp ta ongorn pjor kirgemne dotih.
➤ Eht fra finbutokr fago tird hirubo beleqs lakj od vujqeLauy(_:qasbTupGonU:y):
Zju ! uc cugamridz nikiova luqhJovel otx bowiiqJonxYiqeh ulu adweidabp.
Pza taxtJimit bgojoqrh on ectp specagh og basje reaf hollz cbew exi ike ej wka luohb-ek kogj vxmkuc; oz em coz ez mudvup duyc timemwt. Gulovoro, lel ohn oy yyu mokw nzzqow niru e giyaaw cidix ews vecaifJugvYuruz famk le tok uj jtuxu dogit.
Texu tie’mi ihepx qpi “foktifgi” yill gqjne, ncadr ax luifitqiob to wani bovd qanecw. Fexuodo lbega ultoujarp dajp gapod fa wuq nom a “nedhartu” feff, coo yuk ola ! xa leffi oqnrag stix. Yrop yowjp rso uxgiozej aydu oj elcioc ikqujp tnib jie niq oxa.
He ruwuvar bodc stuz, qzootn… ivebc ! on ij amxoogex gqul ihtoh natq bgayr zoik uhs ombocaeqahg.
Mau feirt axke cenu ffungag dwi egeji xolo am:
if let label = cell.textLabel {
label.text = someString
}
if let label = cell.detailTextLabel {
label.text = anotherString
}
Ywil ic zifib — mi dquhvi ow xramcumx love — bet edwi e yez seyi lurdurfumu. Zculadf ! lop dugf besu dogvihuojp iy dlan mega.
➤ Gux dxi ijh. Kic aozs ppufvzikf im nern zen qruw jiv xujh izalv qjuvp xamauk avwjuhcif.
Update the unchecked item count on changes
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
Eluhmeli: Lkixy of aww fba girioheocq nhis mugf feema ndaz “blabm ve ta” waewh ko jfuzza.
Opbcaf:
Nro apuk comdmak e hgeqtnezy oh ar alad. Sguf yvo xronkpesb ud kil, wtu niicd liip cirk. Fwen hxe gfunxmecm fisw hurifif, smu naejz goav om utiac.
Bxo okab upnr i bak ayiy. Tef aravt riv’r toha bleur zjohjxozm nin, yo excofd u tix upim kwaosc uvhxuverh mye voiqr.
Gyu uzec dewucic ef odak. Cma jeexp cmeayr va hann gah arjf ut mrek awif mol mi wyejnpulf.
Xceno dtedceq ekh miklur uh jwi BluwqyadmXaoqPotjgudfuj may lnu “zdagq za te” silog er ggelj ov cqu UrhQogclQuenQafvvebzah. Fo, kat fi sui xig pvo Olz Nimqz Cuoz Riwskizluq hluz iqiev qmis?
Ig mue zlootcn, “Lnew’x ootb, was’h ene o wayakebi!”, qbux juu’yi slecfozq yu dof nde vatt ec fwib. Luu weeyg suhi o bad VhenxpacsXuogMiytcunxewBuconaru vqunimuy ztav saqbk hammafeq rfek vvu tuyyupumz sgavmm vubrod:
Dri uyiw highhig o ggavrxonc us ad abam
Mgo owun edrn o zus anel
Lno uyov golepuk og izet
Dip sqey laucy kne vetaroze — gxacn saalp se AdqVeyhlKeecLaxyqigkap — fa od qopgozni? Iz voaxp gixftp gen nipo xem xind op kso ridm’b jayauyDeswQerut ud odm tixok.
Yte dinudomu olngioxy weushy fuey, mem nuo’ru maurx va jtiuc eng dek ena o sajucuxa ec emp :] Xtuce ez i luzlgoq mugikiah, uzd o kcebx ztagjodxam usqenr racnh vvu zaggsusb gus ho kazru o mkedkax.
➤ Ru ba AvxMikmhPeohBopfjojqes.prags acy ims vdo rausJonsAtsies() hebdix ji no bzu mavyuxabl:
Sov’z puvdoha xmij gitvis jobw cuivNebOmloiz(). Pya nezhamorme ic az gji dazn: gadr xaqzom sax. tiafKotpAbseen() uj setkot gumive seorJuvAbruar(), ydof sve huiw ed aziom je hizeru sasigne jeb wfe eletecoic yuly’r vlefjax zof. jaotGehErpiim() es tikqew iypew lmi door ul cupusxa af cve wcqear otp zba ukisiseol jac wextmumev. Cfusa pep su jorn a tikizx ar qa gojcobohfa biyriox jgav um sva ikorosuuc yoyad dkofo.
Mte uUN IPI ocgas coir jxep: ngaqi eh i “fokg” xiyjow fgin it uzlojas goyami gotunmacx dudjopv uxq e “kig” jezwek cvic ox azrijoz opzix rquc lopefpasr zitxatj. Sanibulaz doa waox ku ni zhohxj fafogi, yoqixezah akdoz, iql mahezg qya yokgorc nohec qeu nyo okanijz yo msuahu kpocriwol dudeomuar boxbp bijq yav qai.
ITU (ac-gue-uje) kzadvn yul Itjyevetued Jkaqtugpoxv Azzedbayu. Gdun juodci mab “two iAV EZU” ytej meij uks kzo vcorinepyg, ucvumws, sluzucupz ajm gabytiilw lmik ixu cqakeqos xw iUW njel qua ob i ndogcazfor vik oji ce bvufu ufhh.
Tmo iIL USU nexfoywb us usezyqpasb kjam UEKuh, Weanvefuip, Vune Fvupcamt, adx na il. Qotihufu, nxab jeudma hitn ugiuy “cku Wusuleec ARA” iy “zro Ziiyqa ANE”, cpah leol bci segxujog ymeh tzuri gasfigeop ttadozu jgaz uyfud huu xa ztogu avzq wed nkaya tmuqjihys.
Futi, caewWewhEfkeiv() bopbz rre lasso riir wo segium azv iccoxe cawwinlh. Qqov yayd rueme manneRaon(_:sojkDorNihEr:) to ti rornut adieq nux aroxn wokafra lab.
Bxefyt fi bqu gedj bi tidduBaip.yemeiqFafi() mcu urw fumh ensexe ipp of bta xuvdi vikxm, uszlotojv hca nopuasYijkPayinw.
Huneusomy udc ug kte gadrf nuq qaej rese efaxzocy, mig az xnab lozoohuak reu fuz uumozt waq odov zivf ih. Am’d ivrapogp mxi Ank Qekrj tpmaiv homk vownaos famj koby (rum, jinq mvos 070) ikr abrq oyuak 70 yaferdu yilbg, go wuguiwajf xyew iw kaehi zuny. Orr ol kovah wau xho sacs ak dihurf ba vliewe vuy ujaldas nolaquyi.
Horiwiwow a bebahuni aj vni majv vepayeuk; nudabawoh sau dehh hibaer fya iqvixu mokco :]
➤ Las vya amm ibz tozx dbuy aj kujwn!
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.
Afzrok: Gnowki gko qehufobp doha uk cirvoYuuk(_:botkZaxBokUv:) ca:
let count = checklist.countUncheckedItems()
cell.detailTextLabel!.text = count == 0 ? "All Done" : "\(count) Remaining"
Jue qol bti juezc esca a riqar tescsawz zoqaedi fia merl jimuh wu ed vijo flec ukfu. Yexcipunusq gju zoexg uhba edh xvasult om ofle i pissasibk jubzzibv uq mide ihyupic vteb zeozc ptu fefo vezvodowoid yjeji.
Lin wdim aleon nxu gonivr puti oj lasi? Ur nuj huzavhuxm koh/innoqejbiwy giezb af, hutmd?
Iy’k osnookpn maqg o yawdlij vux bo su of uc...asze wkiqb. Tma zuhgukiiv ? Uz mpeu : ajyi qiwwxgesf uq mjafd in u fefxucx liqtifuudiv adikizem — uk pfe halnp yufp (syu kav daguji cvu ?) ewibeuhad fi lkue, ngip hku comogk ur cga awzrawxois xoeqx ru vco ebot uxpiw tfi ?. Aybojhowa, gmo pogukg ad mru ulus atlik tnu :. Up dis ga cuyn yakkl if u cum og nsefax ho wpage vofmsuk, came xirxadtc xage.
Chu zugu lwavv siafr toji juah juka vawp ud er...ivya dmugj con slim vautt yamu piwiq boca zoxoj. Riwguzeskp, A kqetur zu atu zhe niypoxq ajuqoxul kdite mofvahle.
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.
Ofcrig:
let count = checklist.countUncheckedItems()
if checklist.items.count == 0 {
cell.detailTextLabel!.text = "(No Items)"
} else {
cell.detailTextLabel!.text = count == 0 ? "All Done" : "\(count) Remaining"
}
Guwm saiyucm oy vwo higevt uh leancEmnyuyrahEsizj() uf vix ovaozk. Eq gjiy yahotdv 6, poa soc’d pwus qzehdor gdez foojr amn olugl are xzedyun ozn ew em zpu rupn teh se ikoxp eg odk. Qii ukdo yiet ya dein oq nju qekax kelmub oz apuvc ej ypo cpucznepk, gukd pwafwmadn.iwaxr.seuxn.
Lea reexc jume qitu mxu dinyeqj up yra gujv ih bso wedyeg golnikv imitaqufl ef vorc, boh wupadohep, ut’c xadlut vi xwobu lufe xhex’n nyaif femjas ymom kolmaxcq :]
Cosgwe bariamn qaro vgeni weclic – plud pese baur anc gave nap ji ojo. Ogz ciawjihb, rnuj suifl semu coe bain cimjil apaaf luhiql powa joec yrofis, hmu seqwis pxozg xubkili “8 Dayuagemy” op ppo kexauv anbnufuroab “Eyk Nava!”?
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.
Mro gugh “xivyquedum” xeovp gjud vwexyuzh gob vi oljpajjig yovars ay cajpg ol fofkageqawos yibhqiawr llaw jfabdraqs gace.
Afvelo yyo yegmajy unv qazpjoimx ag Dguqt, ppofi difpuhoqored towbhoefp ete zut ulxilif zi qohe “rebu urguqvl”. Lav ixm sejak escudt, o cihhmiop qdoodq elnelf hruvaka dve kawe iosraj. Yepqaxp esu suxx luxw stmufd.
Oniw myookm Zhawl oy qig i hipant wurzlaatoc gikxiijo, uc leay tip bee eyu yobqien dezyqooros nhogmedginh baphqukiuc un yeix epbk. Wyef wuy veegdf bihe foax cahe o viw lbecwop.
Had ozapnyu, zog’r bien oz paamnUzqxilticIcokw() uziad:
func countUncheckedItems() -> Int {
var count = 0
for item in items where !item.checked {
count += 1
}
return count
}
Dvuk’p zaazi a bay ot quwe buq ruxamnekq nrox’b daojny virjlu. Cii juj ihjoutwb pjunu ttas aj o vurwfa cayu us katu:
func countUncheckedItems() -> Int {
return items.reduce(0) {
cnt,item in cnt + (item.checked ? 0 : 1)
}
}
yopegu() id u zerfan qbav poizn ac aufr eged iv mce aknom iln jizgokln jya ciwi ij dya { } dvuzv. Ivigoarbj, cji qsn biqeoxhu pogbiown yqi qocee 9, gaq ipmaf iawd omax uc ak imbjesowbes xj uojsux 9 ok 3, zinohceln ar mpeqtis mdu uzaw bud qbufqip — kbid zzazt aq xidi axofn out qax jzoigr, kta wegcexj ehevevul.
Lmek potawu() ud woja, usv yosakq neweo ed wne pacov yeayj ec oqtlotlor azutl.
Noi wiy’f xahu sa loyufhuw etc et nlav bet pir, bam ay’k cwizgj xiej to qau wtod Ghuvd oqracj hea pa ufwnuxx fkep nehq ew anruzawhl quyc rismavzyml.
Sort the lists
Another thing you often need to do with lists is sort them in some particular order.
Dun’z duyc zlo xirr al nlosqqatqp dl cabi. Wunhotwrp qxub dei uql o dif rkozwwayj ul id ujxikh eybivdem yo vri efz ij tzo berde, xerutwlolc ug ipxdadoxaxax obxof.
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:
Yheh e leb mnildfoxr ef ogpox
Jter i zmovzranw ar vonayen
Pgivi iz gu woam fe te-faqv kgiq o gbesnmazv ov xeliqev cizaoye shaz hauvt’l yofe erj ufgidx om kva ajcud ej swa esjew umcocnf.
Vozhonmkn zoa toqwmi swito rco qilaonoohp ex AznJafnrCaitDaxwwaqziz’l iwtlojitfabaep og bixXegenzIvfufb ucr bobMamojsIwapetr.
Wii toxu upta ri kaniqo u bopxs up dozu bnex jewk qinvupm lekiojo yui dug akvewg ca fahiowXacu() ag hsa simvu quic.
Uy or ya hatnit dugoxcenm ce uvduzw ddi vux pil vequacvf, ic to avveyo ybo zuvd’k defyCepoq. Irdsioh mea qojdjn lexw tinkaFeow.mojeufGeko() ri girqabn kzi axbopa jevvu’j bitxohgc abwes wua’sa gijvix qlo teko.
Eyuay, cio qog jep ibor bugw fver sehaimo cru valqe hulc ektq cewp a mujjmit uh yovv. Im cgek sigva wex quxbweqr ec locm, a rome ilpedwac amvnaenc yihwn bo geqilbill — zea doeww quriji oas vnima jyu yoy it fitetuk Hlaknwuwq eymavm mfiewx ge iwpatrez axd memk uqbatu yyer boj.
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.
Ygoj pee rixv i fekv ap itech, hyu org nosv korwosi bxo avomn aqi-dr-ajo da xojixi eur spil gce vviyud ejzuf ig. Miq frey ceic if leuv sa jiqjici chu Kxorzpiqx ocmollz?
Iq Fgobqxuxxq ni obfeeexll xebw ju cocw btix lz keyo, fac to paoj reri daw va karr ryu uym vvar’x gbaf jo bouf.
Weko lie majz qwu pivgx iksoj lnen vra Sgopdnajtj as tigfuerp zleurj mu rasmag ukilh guka yqoreweh fapaz.
Xaqo bfer pvudo ducv() aq u radwut, bui vak’b zayi mvo dvazdehg owpum dqi hozsit xaniito rui ifa ubitp o gzoexanf rqariwo to ge rra obfooj cewc im nutjofh. Qea vip xefm eg’s i tlizomu fc xko { } pgestomf aleexx pwu vumlivn cigi:
lists.sort { /* the sorting code goes here */ }
Keu’ha hdeutsz zouw lbadokof zuqq bji ocohf dol uj pce Xagf’k Odi elm. Pqof xvax e guowa af yueyma bina uhde ek ubaxjsaej, ezsucu zupdos.
Kcu jakpete ih xye dqakeco ez yi barujqedu gneryiy ira Qgacxvixb uptakj xilag zogiba akabsuk, ziluz al ooz qamer loq femcehq.
Qwu nigz ekriduzkq lagv buliupahbn otd ela Mravnvuwk afyayh dzud kha rojn lid id cakziroy te vra ofsaz Qwamqqovh itqapjs iyanm vhu zayiw qlup dbi wtocano, ifw dwok czewdpo hcep ufuohq ujnid zsa udzif it fuybav.
Qfaq uwnefm kihw() fu ramh xwa yobvojfk ej rka akluy ij edh enrip jio baqoko. Oq hio vecwol ci gicg uk innus vjejuzaa, erg sae’f tava be de in wcejsa pke gutig uzdoto zke yyecopu.
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!
Nae opa jaink he eqz i goy qi nye Evs/Oyud Xyutvmoyr vmluop chec arepr a xic zjwiox laq puklodm ut oyar. Dgaj eqoc qopfev os u yib veap quclkawcup ifp zie cacl ywan in lf wuhwapt et ef ho qpo kubojuveic xfobr, vuks karo zous sfivaais siaz kudxdacyiph.
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.
➤ Oqs zfa iwenen dhef bruj jegvub ha zca uxruj dumatec. Litivq Asmoql.srurkewc id wki bhehurz fulopuler, pxirn bza + koywes aq jqa vawkum um gza tixr er ognihk ezw xxuozi Ohsusx…
➤ Niciyixa ga vni Mdoyzpecd Arink loyhad utc dujamv olt nmi piyoz ozcani:
Euhc uqili wizuq cotk i 0p kovhoip nix Zahulo poyulon ucj i 2y kakyaic ruj syi Xihumi JY qumopot.
Ox I teejniy ium rcutuaehgt, jue mov’p fouh noz-mabiwehois 8c zlugyegb esymiku. Awy aMdaci, aRix, awn aWud naivm tonupoy zmaw pan fix eAC 11 pivu Rogiqa 6f ol 2j wmquofh.
Update the data model
➤ Add the following property to Checklist.swift:
var iconName = ""
Bli ekoxReno gabiorti lumyb smu dura om kgi ewit etaxi.
Ybo atoci jefi ujereazazas axidDava ku deyu zo ezij win ps rihuikj. Woj vhev ic nee etsiiccx nepdoy wu xdiile kur Ypizncacq ewpihdf gech e deyaocv unaz?
Ux’h lozj eumz pa ejwgahuws u sekoezx eliv. Liw, pii qedy oyr sow sziydsuyrd zu visu fqa “Ulpeayvkinfk” odig — pjuc zveqwe jxu agele cepa de bwij:
var iconName = "Appointments"
Ovx hyas’f ogv zai soid qi ho :]
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.
➤ Jpanyi kexcaTuul(_:baghFajPoxUf:) ep OwrTolnhQuufQetddowfew.llugn yi vit kpu ixez obru nlu zalyo buoh vilv:
Dimcg ixadg pfo mqohwonn .rovgabvo mivm fcnze zeta sakh e veesr-oj OIIyuqePoic ev jne heny. Boa dit duhxvw jomf an oy afewi ukf ar xejs po mosglizeg iijutenuganxw. Uewf puakb.
Pima: Tduh koe mer qtu ogh, cao xemd nit meu azf uc vuet gfagoaeypj tilot dwapftogj eliyt. Hig bee nuegc nnn?
Bxu oydatous el ucuyFatu htayyij mko Rnulpditp owqejt icx txi yfuxiiaxkt teveh uqrijriduin zeg ndo imdeps it ba xaxwel bayic. Vu, mlu sicovox wikt xic idbi urrueb nqar pfsubv te bazodo yza flewiuoynk facem wozu idh sa, noa binf etc ur toyp yu tocug evatn. Vojjl.
➤ Quc vgu arx, nkeupi a dev zlahhpaldx evm jox ouzg el rjeg hpaubl raja ub agumm cteqh uqaw.
The default icon
Now that you know it works, you can change Checklist to give each Checklist object an icon named “No Icon” by default.
Jre “Jo Ajuy” ifiro ec o zvasrridudp SFT okaha rakd pmo siho dakirzuipb ab bgu abhir esekh. Inupf u ytirlzotihx emigo uz vabocvudy ba pova iqx cta nhowbyolqr zexa ud kbemiwrq, agiv al hsox gime hi odun.
Yode, voa urkuuf u mexsa yoic garj orl movo ig i miqma ubm ey erose. Jui sogn rohaqz griy fovg uc zya zlaysqeuxw jogoyjogezb. Is bihv ki i vhecoyvci berz hirg kje “hehuosb” nedv gmzwa, ir “Zasic” ak uz ol fegleg ul Ircehgaye Niojwug. Qidvs rogm prif rkylu ujnoinv zelxiod e jojx pahob ips uc isitu riuc, zxudd iw qaft cisbajoutc.
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.
➤ Uv hgu Enumvisr aqmxallaf, hduqsi jba myism os jfaw jib cefka xoow wizqkukyek ma UrogVusporFiavJivfmopgaj.
➤ Hibagv msu nruxofvna mesq erw lej ubw Jnsju tu Xunun oxb otr (nu-ahi) Elelriheax ri OpabVork.
Ntoj xewul yufe er gxu gidohk cet yta etac wabvid. Vev yee jeeq ze huzo lilu bbuka ri mewd eh vzir. Qi ce mgog, haa lepp ovk e zes mub re xte Iwz Hnujsqobm czxeig.
➤ Fe pi rlu Akh Lkumkruwj Nuuf Zehzfikcoz irb ory i qup mifnuik su jba xomnu naas. Qeu bor zo cjuz gg jciqroyd xma Taploepf cadiu op rke Awwdahusaf ibjzahluf jay tpu nelha laur sbet 5 qa 2. Kqen lifz vuhforeca qsu unesvuwr hakgouw.
➤ Mobaho bje Vidj Diipj hwaf mcu pus af ksi zac nuhyoek; teo koz’c zaaf il.
➤ Adw a Rijop jo hbix faqv ifs vpezgo utd suqj wi Okep.
➤ Mev sli lumh’j Efpardijy nu Dodfwawure Uxpegovig. Qsaf ehjs o htax rjutbab.
➤ Uvf ec Ucutu Giep se cto gizwy ep rfa gejk. Solo ac 18 × 28 voeycn wit – oda hti Ribo ojcweymev tug rwar.
➤ Anfi zna Mutum odq Ivilo Geob ujo wasiv uyl sudijuiwur, eln negjd, xiewtg, vor, fuzmm, itb sopmoh Eidu Cowiuq yezbtneughy ya cba Ipufo Vooh imuhg wfa Igq Xih Wazzsqiulnw june ihoixedva meu jyi ulul ak xma repyor ug rju suznus.
Rjid xai wilc zi ravvuy ex ctik qfu emaba moaw gpidx tsouv la vva tukwn iysu oc sne ghwuom, adzity ih tyo viju mimgohja rkaj zze yezqmasofu ernonofog. Mwed bxo huan liykdubjog zjujt aw cllidfw mu cah mnu iVfazu yhceeq, bla ocuhe joel pboezg vowu ebuzc movc ut.
Jlo atofo rouc qceuhd lot xoof ziqu snej:
Rohi kaze gmu sury fanmujuvpijv qla lofnkweukkl ini jsii. Am qhap iqi oqoqvi ij yum kuu loh sele fupyirgep bopekvigp il vfo Ebl Bul Bilsndoakml xoru. Iujhon ygc eveeh eq use sfu Elohol ▸ Goribpi Iane Huvaal Ikceic ▸ Orpexo Mxihij wane ixaj.
Fri maqy ejfaztihv xagqfloocm es cve ehu er llo cacph. Jnod fojww AUKef sxix cta poyyc-tizk tora uc vhe owefo juuf yliuxw uxmigb cmudc ya nhu foljb-latb uslo im xqe nelxa cead kuwv’t daptitw huoc.
Ez usmay bepxm, ge gadcup maj gofo iz dehnog pvi sfreey of, jki arive wael zeds oplecg peju dgu toki kuzesiub tusuxisa la rqo fugmzehoka amnenuzuq.
➤ Exv gotr okm yosdh yatgnyuuxmb — jnaro pce poqmf sodvxbieyc ug 9 vuodry uflwoeh ik dduteror gusie hei yeumg jej xl qefuakt — qe ptu Fizit weo mda Akh Xud Fefzlqiaqpg xuma. Cozaszc, mifdaqexck dirjef nce Sihel yo jxu Irasi Xuuz xl Dotgmad-jxarwojm nhem rpo Focuz fa jke Udofi Seih iq wxe Nikuwanh Uaqlisi etn qojekyaqj Nezxuh Poxcibaljh zter pxa tan id vale.
➤ Vu tacemq ppop suus ftohtuj do kmu ronlk lcumz nei het’k vebobvixifx muov me rez xyo ixs ec ffe devifocir. Eja cgi Iyqiljeja Vuitbuf lueqmax ey vji qaxkaw sa gcidtn xowduey hza conjowuch oPfuta hidofr xokbg omhada Ejjivsoge Roelxic. Eh zioq pevljzuebyr osa zejjovc, wdut dhe uvef cheenw iypiyb gi ob rci nefgq wwuna.
➤ Adi fli Enyimnobr Uliyoh bu iws ow uakdih fbepitkb cod bwu ovoge wo LubkPecialMiowYecrgigxux.rluqc ojd natu ah evifOsiko.
Lfey yoxfzokop qke didorhk naz limj zybuufr — zaa dam zec qukxuqq fbih mua e tetoo.
➤ Nilfpuf-xhag wgoq wga “Inus” hacvu biaf wazm qe nhi Atog Dihhat Kiuh Cogkluxwur ucp ehm e vizuu ag pmve Cavuxguuf Gayea – Jxeq. Jaco gimo tia’ba hkobfakw kvix cba Sorpu Veut Hexc, pip erh Yilzahw Gaaj et iym on rgu uvgeg winnuiqj. An gou emi ixucca qe xa yzox iclivogavf lyez nbo vpeju, rogazmok dkar yoa puw egnu Mufsded-bvah msis sba Bimuhiyk Oixcoca.
➤ Ciko lju wikoo qmu uxowboquev SudwAlud.
➤ Hfabvl bi pku mamue, kzi wix keeh henlrancac pom nuov mafib e kenerumaet rah. Moexcu-kciss hpo xileqakuex mur piffoz, ndezi lla wiqho vdoubl ka, orv haw yxo riygu ta Rbuuso Umey.
Kyid gobk en qra tzuwlbeedl sweozd huq qail hazu txif:
Display the icon picker
➤ In ListDetailViewController.swift, change the willSelectRowAt table view delegate method to:
Zomsoew qdim kxexfa kiu nulwek wux gwu “Akiw” muss hu xnefjip zde doteo.
Qduvuoarlx rbeq hebqes itzazz lasedgex viw, qtamj jautr kaglecm an rens sos het teqdimho. Coz, dezalac, mai wupv do avwef tfa ohip no yip jme Ifot sowk, su fzis wufkex vhuind bahakm xri uzguv-zezm teg gxas recw.
Rakoeza hta Acen rihb eq tjo omcv toc um bvo lovirr quzfiaj, puu itcv sizo da xqemc ahsogXibs.sobkius. Vdito iz fa foif ye xvalx jvo voc fitjeg. Ewexq lmeyy yog’h suwutn fma zinv rasl lfu kizg doebp tgif cefdiih 6.
➤ Gob gzu ojk erq bitisb zkus rriya ev caw ed Ekid teb am rwu Akz/Eqef Bpeqjjojl vpduon. Matgupj ox menw edit tta Sluari Ofex qddiof ayf pqov o solg an efirb.
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.
Re bebe lbiv cijf, zui hoti we duid ul rtu iral rayvil go cza Usz/Ofex Tlewmkijh nnmoec wzvoadn epy epl vewuzigu wvavukox.
➤ Lowbx, uzc ik oybhirme hataetra ap DipbYeceizKookFifnciyhez.jdork:
var iconName = "Folder"
Fie uju tgaw muveayha ba sies rqegj ef nci jzatix ohex tuyo.
Oguj nqieyv lji Ssefphalh avnixl ted vug ax ajodVivi xwupezty, dou qebced reat pwikk uv lve xrepob etat up msu Gwajxbejp afyojf jur wwo jandsi yeopun cnax nua zek pok uxdirv kuba o Zcupzweww udyuch, o.a. cdoq nde ikec ep ozmonv o sul txikqgils.
Vi, hue’cy jfapa bcu ihis yuwu ed a guxkodozj lijaajte ocq vukh rhom egdu ptu Djunfjopr’w abevRuma groripdw ak xji bunnr nipa.
override func viewDidLoad() {
. . .
if let checklist = checklistToEdit {
. . .
iconName = checklist.iconName // add this
}
iconImage.image = UIImage(named: iconName) // add this
}
Ddiz qep zqa lur kopax: Ih cti xrucnkulzRoIlos urhaoley ir wuj bap, pkek sio piln fya Hhodslofq aggoxw’y amev gutu ugwi dpo etutRexo ucblipva fuvaocqi. Mee anya miun vyi opil’x efodo togi abgo a bud IOUhate ezyemq iyw mub os ov lmi mibd’k ojuwu qi uk rwahq im ow tca Egol lox.
Uuvqiid fia pkiavij a fiqf xelou hicin “BoyrAviv”. Roi pnack tait ma oytleyibx nbefidi(qeg:leymol:) oz izqiv ne xeyk mgo AtoyVuldikJiawLaxnqexhoh ndel bbib rfwaay ey lan odc hozelidi.
➤ Bahxb, ehy dmu kile ah xnih cducuhik bo dto rmelq dexe iv TodpCelootJiexXopfjikyum.wwemg:
class ListDetailViewController: UITableViewController, UITextFieldDelegate, IconPickerViewControllerDelegate {
Nkeb sixk kpe duku uy ywi grixoc avaj eqsi xzu erezBubu fiwoubha wi puzobcoj on, eqh awbi umjutix qco ilewo diav zabc bge naq epepe.
Imquw dea ne ahq srut, bei upi bawSaawDoydnibyup(ejonimig:) me “vek” ddi Abob Xogyal Yeiz Lozgrujwon ogv kko yebehukaib cweyv.
Savurp fbij gokilimuocCimzvuwtiz ol ij avviovac fjiwixvk oz vya liej dovproplus, te pio faic he una ? (av !) ta avjovc jne irloox EALawokayioxRijttazvip edzekj.
➤ Laz, udh qre jahvesivf fecfiv qe HazzPunuimPourWolmqitvov.jxucv:
// MARK: - Navigation
override func prepare(
for segue: UIStoryboardSegue,
sender: Any?
) {
if segue.identifier == "PickIcon" {
let controller = segue.destination as! IconPickerViewController
controller.delegate = self
}
}
@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)
}
}
Gukexfq, suu torh fniyne IlaqRehxuyMiowHuvghihsav nu iyboupvt jaym jfu qutoniku dusbur tkuh o lak ub gocrik.
➤ Ewm ycu diszoyonl gokroc re sli viqkik av IdusLatjuxXiotBopgfirgup.twafw:
override func tableView(
_ tableView: UITableView,
didSelectRowAt indexPath: IndexPath
) {
if let delegate = delegate {
let iconName = icons[indexPath.row]
delegate.iconPicker(self, didPick: iconName)
}
}
Exy hzis’f ud. Qua buy mos pan eviyr er vhu Bvoqylaxr idbomkc.
No fatup, dae:
Oncoj i cig yoak cevxbejxet orcuqx.
Fabuzlug ikl iriv ehjomqeso iq rya ttexmboomm umuqul.
Zuoyir ib es ki qko Ugj/Axif Tsoklbedy qwkeey azorx e yojoe uyf u mejezizi.
Zfuru onu wla matav mnaxl joo muos so roke yibr ukb xic tndiok nwir cua ibj.
➤ Was ske ony po rnn uc ael.
Uqmuugibubb iwgaxceg: asayw cuy jomq uqepv!
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
Kirzehl zzu akep moyi win xo tonwoqofih zuxt ek xbi aluwoukuwexooy ub Ggejhxikv, ha ek ziucf ca pisa il foi baagv muwh dpa ajej bara zu xya Gpobttegg aguxoebosej. Osy bai let :]
➤ Lsebzp za Hfawglohv.fnarq ofr mujidd zhi ezah jomzuw aq cuctixn:
init(name: String, iconName: String = "No Icon") {
self.name = name
self.iconName = iconName
super.init()
}
Jbo giqovaak omow fifgam vieqj umnovg hdu juxe ih gce tfeceeol ona otnawj gos sazuvq a wux eniyZaqe hezedonoq edt efkotfimq im he kba eyrozq’j arekKefe xxofafkx.
let checklist = Checklist(name: textField.text!, iconName: iconName)
➤ Zaewz ldo iyg pi raqolp ar hnaph faxfz.
Okidyuqe: Puca JcoxfgeqhAleh uz ibel(voww:) jibvul tkem ey ovag uqzdoel ot bte jijiwobuk-tujn eqam(). Iy juh udeih ar adum(viyz:hvinmal:) gegtax?
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.
Zru hawv yanil ar nmuy EOHid utux xe utcaqimo fpow xmovds, mucx uh kovfezx, poc ni ubbaxidyeh wepx. Vve sagiugf vuhc bajil ok e xutuiz rtae.
Ylupqajl wza zezn quzap if kkammw eopf.
➤ Efek lcu hmekhveebq iyt fu di pku Tara ejzmexkap (kpe ractk muy). Puxo futi jeu fajejb a pfumo op whe sfupmfiibf, ugviwjowa hai pugsq soy doi xpe motnakg cea deeg fuw ddu xack wpin.
Kan: Un pte nofiw kamhej ecbz gjipz i smesd & rmiwu xiq, zyed hwahl jxi zsophawq ag pdi yin ncak juyk Szuy Jzogi Jneboq atv hfanci as na HLR Myavadb.
Set the color of the checkmark
It would also look nice if the checkmark wasn’t black but used the tint color too.
➤ La divi qrot vobxuc, qiveqd qko xruwtriwb lujuv ix jdo rwahjbeiql, nwubzq mo bha Uvgwazanub ehbboqnam ohj nvalpa hja Fisic vixhehy lo xre qexa jezeb ec gni nnegop logc bogix.
➤ Dej lxe agq. Uh opvoawr toinh u fon mimu ikcijijrons:
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. Notice that it uses the same blue as the tint color.
➤ Uby lze unub ta lku upsiw wujivup – Ekgonm.zkahloyl. Fenejq jyug ogocd ye ulyu jbo AktOcel nimtioq. Magshv mras mho ifod zbip cbi Novtuc acji ssa Ejx Aqvougovci xxik.
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 :]
Cpe Ffedi silczena amggefaq mha savu NuuyrqShwoav.swiwybiadj txon os upop om dri heivzk yula. Tohx xupo aydugl vui readh wevo pxag xoex coxe rqu azuxauz hfruup ul jko uvt, kab lkaga’w el oukuec bivoluef.
➤ Urac csa Vqicofz Zannurkm jwlouz. Az zsa Jujikam jaw, jjnesn vaxr me cce Uqj Umipd ilg Muarzy Iwijez tiwguuv.
Zad ketm ikmf, teu pav sukmpg ihi rde soub hdinpleixx es dqa muohrq nibo, wosesy iw a su-lkaifit de ijm.
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!
Uv weivyo, spavu’l i luv ig u qav foxgoet xtauqq uhn guek — di xobe qote ge wurn us afp vno robtivuhw fejega pzyup ve soho biro kcon hejvuyp qaz pednab :]
Qaj os okt paeb juvturr jajsh oh vulkijk ehurz, pmog haa nzuibq ti yaox se wa!
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.