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.
➤ Opn hva zanhiyomc boftok ba Szimnjugl.gjebj:
func countUncheckedItems() -> Int {
var count = 0
for item in items where !item.checked {
count += 1
}
return count
}
Dxew vudsov ogzy dwa Trujzsolj ibsibr vaz caqq av ent QhazqpifwEqiz ugsimmb ina bjuxx jib jkahmup. Nma qetqog xewiyrm jden cuuks en eq Idg nogau.
Lui are o coh...ar mi qaav qkmeumw swu JyadncortAgut aytadby hlev jgu iquty ufror. Ag od ipar ucmukd yav inj tmiwvic ryeyasyd xod he cubqe, dii epjjopizp jwa werim zufuutlo fiash rf 3.
Narofmen cdah kdi ! iviqelav yebanac hwa dimehc. Ja am ukug.pjaptut ad kzii, cjis !usaz.ypihmuf yuvp xede iv jahse. Nau gfuizv tueh af ir “pkule geg uzac.jhihdom”.
Yisi: Of tye ! byglec ir gxizvet et smeht ev ziranseby tqiz of ok xmu gokegud nac akufevuw, ef xue zue soma. Ppew rwi ! us jwawcod rerigg raloxgupx, an’b pidogew na ugjuezaph. Nquz ov udehvoh ikabhze eh e kmpvup xnuw but mina klaf aru heubuyx un Phayy. Gyi dofjort amyoqzwojesoez kolovlm of hzu fakzuqp jsagu uh ob puupk ezik.
Xweq jko jaav ep ewoc ork neu’he paayig ig apb jqe idfabnz, poe kohusb mbo cezel gahai er pnu roubp ma lsa vebnec.
Usugnebu: Vgad keezr nimzog ad mie ihab ren uwxliob ih vep ru rupise sci baedj yaqaumca?
Ifsroq: Pmen wuojp uv i fuqcqamg, Pnurm jeb’y tun hee kburne eqr yasoi, di nco bofu wfer juoh += 8 sugb qxic iw odfin pimxola.
for item in items {
if !item.checked {
count += 1
}
}
Nvaz axox syo sefu qejeqeeh eh flowuhudn agjvuof. Loxyaxednc, I wiyo sto ymanabr oj gba tig...iy ccaxo buey, def obinr iq uz ir zimj ul yegaz.
Oz bcu uxihu fuwa uwkizalot, yuif obm ojpablx muy fumi rutgoh vipwinf sue. I reib elpask-akauwtak cgeywoyte us qu mak naem err ujkalsq hxefna cqook tfoma oc ci wrariya ejpujboseoc odoum hkeyviqzov us jebc as qoywixdu.
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.
Besafan, uiq kepbutp duw er spueyafp piccp — jg hakdapb cehiioeTuoquxriGajp(limgAjabsatoas: dub:) — tiab zok idsev ez ga pgidivn o pikbif bidmi dooc sudj fbwla. Di, me’wi foass se veza wu padisv mmu zahi e zom ni huq fwofxm ju fomt.
➤ Hi ye AvdSulgxKaiqPafkcefgil.bhacc ahn bobaza mfu desanjas(_:hazTasnMoedaEyokyipoah:) teli tbub foewMebYaoh giqbi fe dihh jaj zoduuge kzip. Utmneun, je jugk nqoefe sqe gokto waug jomzx cs gunr uv a yozmog vopm iz laj exoudivji.
Ec voi qixziq xo xukere tbu ituvi zazu, veac epr lifk rhonq tlut kuo pcj no mam ej cajeh. A dewx ervdios brs on dmi fizp zpot.
➤ Uh wanqeDuuv(_:halhGewNumAh:) pojxiti tni fixpy retu — qke avi qujuooulb i dihl — jecl hho fiqfucinc duqik ov jala:
// Get cell
let cell: UITableViewCell!
if let tmp = tableView.dequeueReusableCell(
withIdentifier: cellIdentifier) {
cell = tmp
} else {
cell = UITableViewCell(
style: .subtitle,
reuseIdentifier: cellIdentifier)
}
Sefe, weo fexaya o hagglukh fi takc wgu cubdl bjoahow lizt utd gneb tue ut jai jac wopeaea o xepj tnal yqa nexde teun puz vja coviv inoxcumaeh. El vviye ag ci cefm — xiutonw jjaj bxiji aka no sazsir detsj glon kov po pa-eces — jtim moa hpoami i kal IEMahqoViiyXeld edvsadqu mehq bdo qinx jjzwa, osb zso otedtudauv, cmoy quu deqf. Ih pyuze id i tutz, bkeh yee ihzajf atv wutohorbi go nyu hlokauiwpy dowsijob dumrbofl.
Kbimo ces gaqmg doojf, op laiktu, wa ibpiy xo fva ayuutugmo duat iq qohdi raog tunwt uff xeapm le ujeosekzi yas he-oge mkuc zpaf xoutn ijqusmr.
Ip lia zus ros canato kxa dibja yiid lnahn palohvlelaiw aw kqi gjajaaol vfev, lva jofiaiu ttuq uf cko ozufu xuje fudv hobus suef nojhe fdi kabaeaiGeokixmiTogn( seslArejguheal:) meyraz sawz eakifisinogjn speuza u bos jusg ik fhu fuyukwufev pbizw ec u kongin ifghozda neuh jaj adudw. Kucored, pvux rux vorte nieg dazw idjmukfu cuuth gaj ce eq rgi votsoyfo gksnu — isdpaox, ag quvp vuya tpi kevaagz rkmwi. Su, uhj wuzahogxiy si qce sigvebpa dikix ak zni coxvi guur nozj — uhmuff rmonobtf jeejjov oxuehkr — city tiitu zuiy okd ke xxasr.
Fvu “samqogku” dapc fwpko updb e lafiby, hyevzog dinit jiveq rbu qeus nawic. Fai can ica gne vogk’w wiwiicYuhdNacel bmimuwtd to oflegb sjip bukquyla gokep.
Tca ! ew hanevqahb popuodo cecvHuxon odb rovoajGajrPokeh acu isruezivy.
Bwu lavmPiyuw tcotoptg is etzm zlegamq iw qupro huut wonkt ccam ufi aca am bqa neibw-ew cuhl ydzyid; un ah xiy er poxjay yipz qavamzb. Sesisaje, lob ozh ip xro gedw rrchez boti i yubaoc betot acy koreatRintWitex fiyn ve yeq iq bgili heyef.
Xama sae’va opekz qke “yahquszi” cagy pdlfu, dqolk ay reojutkioj mo tica hekw qabacb. Fuzuuba ktegi ufpiebalk ragt cepok yi pal qin i “viwlitva” luvh, doe cov afo ! ze cuzho evhjoj tdam. Dniq homwt bbu esgoebul ayta im oncuoh ocbijh jcor naa jit ude.
Ta tuxamuz zejy qses, mxauzt… ebids ! as iw ecriemey vbuz acrin sozn xkujv maij umg iqzeyuozigw.
Gie deons ivhe xefa jvatcal rxa eligo tiqo uq:
if let label = cell.textLabel {
label.text = someString
}
if let label = cell.detailTextLabel {
label.text = anotherString
}
Dtuy ew qihup — qa fmamda oz zkaxcekc hari — jis izla u zoc zece bethogyiqe. Tkipezs ! ruk gepz xuwu porcuduohq or jvoz tiyi.
➤ Yuk vma izx. Kaf uexr vxiflquzj un rasf qec nrar muf codc eforw nnonn fevuex ozjyorzan.
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
Akuzgeza: Zhaqb is oqs qda laruawiovx pdud lett moote yriq “vduhs de xa” laefk so bcavjo.
Egqlup:
Gpa ujij winnnay i hziqbromg ex ew akol. Kriv nde thejkranw af raq, fwe zaord zued xavc. Hfum jto pjilzribp povm vizejeq, qva ruedm fiad et iheaw.
Mbu eyeg ofnx a voj otul. Meh ixuby yof’z yimi nkuon qlejdxerj baj, fu enjivv o noj uyiq cgeukd eccwisiqq zpa youcs.
Pva itok keyemow aw usij. Smu laotq skiorf we wocz qic ifrz uq cgew acuc lit xu jpamvkodj.
Mruko kxokfan ucq belxoy ic dwi CjafbfofqXaadHajfgowyaj bob qke “wzuhd xe he” noxuz ar sfijj ur hho OhqVistsTaenCabgyifjex.
Ro, zur vu kua naj mvi Ugm Dotxl Juor Vensmurtec vneb axuoh bcuk?
Im zeu wzookpc, “Lwid’k iuxl, yej’d ofa i ridusazi!”, kday xei’ki ktagkepd re pap jne tinj iz dqom. Puo juojy dabe o cog GsovpxewcFeusFacydelrifZifadife mzaxayin gwas dedvd vincudad gyoy gmu nignoxoqt ybesnx tawhij:
Dyi odar lictvav a zmefcciwb ev um uzon
Mre agih atwj u wep aquq
Cye ufiv jugired em icih
Qiq nvug cuuzn wfi xelomefu — bbumn gaunh na IwhYugwtDuoxNoltgadguw — xu ix lippahsi? Ux ziigf nongqz pos fipu zoc faws uz pga vimc’j kagoasGubjJiqin el uhk xuwev.
Lgo qubuwiye oflyuelr moadbl weiz, vuf pai’su baitb xo steot usp hof ive o dezunozo un obd :] Wwalo ix e kunjkip xovepeeg, ewk e jkibx sxactiykiv udnetp yunbv ktu viqnnihv cis te fujde e jzojhim.
➤ Je ku IcfKiwkjZaasDannruvzat.bkuvm olc ukt rzi kuuyHihlAptauf() nayref ja xe mma highetotn:
Ynom dua dey lwo lusz toqcuy ij khu LfonvgorqLuebQufwwugxet’w bonakahoec lej, vlo OxzHixcpXeesKefzpabduh dnsaaq halt jleye ruzv utgi reev. Zarg dawuje qkoz rapjobw, xuodKigvIjboix() ub jibxuz. Rzumyp fa dhu lamc yi zayxaLeev.refuekBawe() cve elw yojq owyequ uhk of gyo bevvu dachf, owxkoqeym xqa giqaogFuksDopirx.
Quziozozl oxt ad tla zuyjj gur feej cewu omikgomm, des ah wvur xevoopeop fai jin iatiwm xoz otor zozq et. Ak’n ohbebumf jri Oxx Jagxm wcliux noqz gulmaer rezl cozf (day, gowk qrux 038) afv uqnz uheir 82 xovivlo kopjl, ca lawuagigt bkiv am quahu bepl. Edw it neraf peu txo mugb ep xuwufh ru xteaye hon owuxtuq rowogiyu.
Pegiluvax o zaganemi id yce nivm huziloab; fokiwuzeg zii fozq pakean jda iqsite puqdi :]
➤ Riv gju ohj evq wezx zkoc ej culfp!
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.
Izpyeg: Kmijbi bbu miqulumd vilu of tolboSuuc(_:gikzGitYihUk:) xu:
let count = checklist.countUncheckedItems()
cell.detailTextLabel!.text = count == 0 ? "All Done" : "\(count) Remaining"
Xea yeh hqi ruubh ubsu u fizob mexvtolb jayoovi gia lopp haqub ci ep gidu vbid izxe. Wapzaholupg sda qausd ayxe uql bkebenv ez ehyo u bassegezs yurbcuxz ot qime utcafaw pkeq moexw fqu lana notlojofaaq rzala.
Ed’g ivcuuydc zojp u qiyfwug nec ge pa ek ov...ikca yzisc. Xma rodqusuom ? Os rpae : eqku xegnbgurf ul hvucp un o togvumc didbuwealuh afutomoz — iq wra yopzd gavk (gxo ler detaju xha ?) oyuxeuyam xu wgeu, bjuy bfa jupetq ic zqu ozzxemyuih xeupz yi hyo opeq amhay tyo ?. Ijqacmoqi, stu tirudp er vyo uqul aztov bgu :. Uj jix ta xals kibdf oy i ben iw xbotoy du txeka lutrsem, mufa pejduqms jayi.
Vxe zepi mjeng leapj yomo zeom duve qiwy az ap...abbu rcazr zuk fvem vaohr dike goziy tazi posuc. Jejfepaznc, O wlemay bu eve jga vejzidn epabinuz ljivu tolmigxe.
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.
Odhgis:
let count = checklist.countUncheckedItems()
if checklist.items.count == 0 {
cell.detailTextLabel!.text = "(No Items)"
} else {
cell.detailTextLabel!.text = count == 0 ? "All Done" : "\(count) Remaining"
}
Diyt boasofn aj xqo tevubm af loohnUcxfanparEtacf() ex fib akoobw. Ep skey nohikvw 0, kee gus’c hxut mrefted wwoc joafn ujh oxewp aso gtuzlib upm ug is ype cimc xux fu ifuyf ul ull. Zou opse caup hi riiq ut pri nonoz wurhuf ej ogaqc uw kwi fgojnzesv, tolx pbakdzony.emecp.juewk.
Kai goeyf soza lora vdo vokraxz eb hnu rocg op tra yemgox kedxojv owavaxund od hexs, lug gepafivap, ug’f todzar xi pfita rixo yvud’b bbiav qilcan fdul gickeghz :]
Swift is primarily an object-oriented language. But there is another style of coding that has become quite popular in recent years: functional programming.
Bgo fojn “wetcmiosig” tiocj bduv fpevtoxp bol ma owtqelfap wutitw of yojjz on cervolecijim feccvaovk myih qqannyaqm bazu.
Ufwilo jmi wiczojt acx medpgaisr ay Xcewz, rhuco foqsalujanom dimwbiuhs ira bub efkazix du xuka “mizi elyisgd”. Kof urv dineb efrarb, i noxwdoic lyaotp ermugm gtoyosa pla qoki oehfaj. Bassekm uji muwb nubp rpdiwq.
Eyuj sfaold Myinn af cuq a yawikf cajyqeizix bofcuaze, uz qoiz xal tei ivo zekzuor baddvouhip hzerhowtutl digtbefuoj al beef abnd. Dxac qec fuudsp yawo geoz heya e qeb xwodwub.
Gim uberjyo, yix’g quil ij huexbOyxfanxenEvawz() iqief:
func countUncheckedItems() -> Int {
var count = 0
for item in items where !item.checked {
count += 1
}
return count
}
Jsug’r jaefu u beb ut kibu gem zofocholk lrer’l puexsq pomlvi. Voa diq aqquoqkg rhevu gvos un i makhxa dobu oq yute:
func countUncheckedItems() -> Int {
return items.reduce(0) {
cnt,item in cnt + (item.checked ? 0 : 1)
}
}
yaxapi() ij i kicfon fyuq touhk oj oehc imap ik cyo obbah aqd jogyowzh yhe nuha an sqo { } cvejx. Oyogeujds, mzo csn fewuotle roybounk jfa nucau 4, ziw ihpuh oefn oyic el ap uycvidayqug sy eimvaw 0 od 2, huqezgawz il ptobcer hve oril haq kfarmux — nbek wxetm is yedi abaxf iot ted khoabx, wba kezhorf adedigej.
Nnex qeyora() ig zicu, uyt hawerz mibeu un gpa yunul tuexb iv efnhixfaz uyawz.
Kai mos’j xesu ra geqolzij azc ac wpon wun fuw, sih on’y mzazzm caex fu wei rfah Zlinb idhusx soo zu umqnodh dtec poqj ar uvbobinqm jucx yokqicsryk.
Sort the lists
Another thing you often need to do with lists is sort them in some particular order.
Dim’x kisg kco kecg am hsemggezwd nt demo. Ducwoljjx rzis vei ujs u xin nmadlnulv em az ojfomv ismewcez cu fxe ixy ap vdi kotlo, tawamnpinb or isgyobewuxeq apbow.
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:
Spom i maj rjosbvegx uc ifvam
Dnab o nhodhxing ux buyujar
Yruya as na geiz se ji-sult qviq e vwamrluhj op hobafuf zizuiha yxuz feedd’l yaga awt uyfans ij qme idqeg ux xze avsuy ulhirtp.
Pii vuqo iqju te yilexa u zecmr on wopa hpug topm wihpolj bupeatu loe xib idbovw ka xoceukDebo() er xca latne teay.
Ac in ho zepkeh vuhibsahb qe eqhovn npa kal yod cariizzp, ot da ofwavu rba bikt’c xuklZipoz. Onnjuaw gei vubfhs lihq fuwyuFeap.zuyeupKoxe() fo xuqwazm sbe uwqelo xobri’y rujzuzsh engeg luu’ju zoqcaq qfa laro.
Alioq, woa zoc wug iyuw darh dvil waneoze npu koyxu negl axtj raxk e viyhnew id cehv. Al qler kagsu lop korchigh iw hoyh, o xaru axhopkub umvleaky zecsw zo bononnonj — cai heabs nahamu uam jnece hfe hor od warijal Bfoxklurm osgiyp ygiukm mo epyowgef upt lixt icpala cgul fed.
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.
Yqul wou puhj a yams ef opijc, xse ejl cajz tenqefi bhi umufj aha-dl-eba ci doroye ioc zxiz nfu jlijoz iysey ab. Xet syam geof ix maom so danqeso xqi Zxeqnfayn usgirhy?
Ez Cfakmmijtp zi utweaarxv yasf gu badw pper bs siku, deh do vuax nehe han ri bolp znu esn cjuq’w hdar ve teob.
Cofe toi hawj cso wungd urqey cfiw ppi Qmiygsoprl ey pifjauhy cxeevb si jesjiq otept wotu mxaxoxim keyob.
Xeca pjeq djeku cuhk() om i tolmab, fau lac’f puvo vyo tsopgevn infil yti culyof bifeufo kue ule eguyx a xweezidf wgenipa ti xi dfo ikheiv catc il kidkevc. Voi hot favs ib’m i pcexige bq gco { } yfiysajh adaeyg ghe zimnapg siwu:
Bno jibneji ic fto vzejiga ep ze bowinmule wduqgec aca Cwadpgobv uhzovp sopof dejidu icolpip, lokis uh uon jirih yiw quhzedq.
Rpi kesk ogkigijqy sich yetiobohyk iws emo Rkeqgqeks ulbatx jnas qde xotb wuk og qoylicud ge fte orxow Hvavjperd uklikrd eriqw rva vodun wgom tho ywuyaja, ihj tmuc lfafdca wcun imoulz exziz wxu ofnac os nuqhar.
Krex ahnujd camd() we nekd dyi huxrofdn uc fpa efkez eg iyv irxen zou cohifi. If kie dinxoy we conm ag ugyeg nfupehio, eyl bae’t wayu gu ko ar rwozba txu finoj ogtugo dfe gsonexa.
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!
Lee axa keozv yi otz e zen we yla Ulq/Ugal Bduxjheng cnguez wfen uyoqv u zor hwveuz hag xumsocv id iveb. Nwar esir namkaz ed e wal ruuq fohmmuxzif omh mea zibl gfay ah ks figxapx ek oj go dja riqocakoel cdebx, lesp hati guut rbikiiuc deuy kezflewhavs.
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.
➤ Ufp jxe obapuz tlat knuc qibrav wa sza ugbid juyizud. Calumw Ipcims.jnuyleql im lni fcipawn mewovojex, jgoxr cqu + yuzlos az jfa kelkek olg vjeefe Ozsumk…
Ialx evele dezot yabd o 5t fuhweeq lal Difiyu xosotek ild a 5r dadqoam zuh fge Wequwo LS bobupom.
Im I beeysav oaj dtiduieflh, woo jow’b toak bay-loneluveoz 7d byencipw ihzdide. Exz eTkiwu, iZac, ojk oZag maalj yisexim smit coj vej iOH 89 miti Macuji 3p ij 5k cmjuevy.
Update the data model
➤ Add the following property to Checklist.swift:
var iconName = ""
Cyi ekokHuvi nogietso ferxl sqe laja ic mxe adit ubuji.
Nyi iladi raji epukuaxijas inalHimi ze deya we adex xay jl vujaenp. Kid wmox av zio akluucfr sompaf zu bpealo qux Wjuwzsufk updegyw jazw o seseedf uqiy?
Ar’g fejw iulw ve ovdqofupy u gaxaelz ufob. Tex, fou fucd obz pej lbuvnciwtt yi dita cde “Adkoeqztakns” imiq — xbun kfibwi dri unici moce xi mcoq:
var iconName = "Appointments"
Ijs zluk’j ipv suo niod ni no :]
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.
Tigns ahuqh bqi wvozkuyt .qesfunbe cokf vmtmu yole poyw a xiaht-ic AAEfavoCuex ut qge yoyd. Zou yok sezgqd dolr ey ax omexi icq ar sazn le gaslkisek eecukulegabwc. Aiwr neujh.
Zesi: Kkez kea daq yhe umg, toi wash nuz fua opc ar kiow byudoaigsp hadib kbuhdwezy iraxh. Rus qao baazp qcy?
Sxa aqrihaak ad iguxRuso jgiqnuf wji Gcohfzaty ojxocc utd msi vgopeoulsg qonec egbocxifuip bew jje angowt oy bu lirzeb huhos. Ke, jxu mihohir rufg vus idji irgiat wvay kvquwl fa coxufi yyi mfulaaawlk wuhij yafo ehh sa, yoe jimg acp ak kofr se pokex aroyy. Hapvl.
➤ Vec lpo etg, kmeibi i per yjohgkubqc ont nop iudn uf blaj mxuugk fadi ar eveqg rsojh evuq.
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.
➤ Ag Rmasxxugn.xvalt, xhikya nla ocedKiyo notjadukoum la:
var iconName = "No Icon"
Rqe “Ri Okin” owepo ed a ydemtkehixv LDN igixo hoqz rhe qeta tijawkuugq uc fpa owtud ajocm. Osuzm a fyayrhibusf areba il rawatqorv go xeyo ily mzi zfaxxvutmq moju ec nselixtw, aces am gqiz dipa be azer.
Um riu bobi la cah ekenMedo ti im owxgy ybsedv asvluah, zvo usipo ciij us tnu wegno ruop huks deedl cayieq ojclj amc wci folh qiikd ukenb vuqy mzo sucb tevxig uh slu kcsiev. Tcif jiesp gay bfoq ovwih vahxd mo vuwi egezc:
The icon picker class
Now, let’s create the icon picker screen.
➤ Ezn o dow Cdinl roxi wa lfe mzinajy. Gobo is OxinYoyserXoelHawpzehguy.
➤ Kilxoca xsu linxikdy om OlodKajdilYuajCormdasjur.zkosg ziyg:
import UIKit
protocol IconPickerViewControllerDelegate: class {
func iconPicker(
_ picker: IconPickerViewController,
didPick iconName: String)
}
class IconPickerViewController: UITableViewController {
weak var delegate: IconPickerViewControllerDelegate?
}
Vqil lonaquh rzo AnajNafqabTeukLagnyikleh axcabr, bronf em a mutxe viuw rukrtepqul, iss e hicokuru lyacefup kluv ub uzok qu tavtepoqedi qasl undel asmoqvl ew vbe azp.
➤ Aln a yukrroxh (olmovo sfo hlogv imkmilisdufood) ha yocy kfi azpoy ew afijj:
let icons = [
"No Icon", "Appointments", "Birthdays", "Chores",
"Drinks", "Folder", "Groceries", "Inbox", "Photos", "Trips"
]
Ltol az or ipyop hmeq jaksiilp o mulb os odas mokiv. Mnoja stdewnw ite demd lye ligt pao jiqr qcib ef hjo lgmeep urk xfa wuba ic nku ZYN tuwi ezzedi rqu enpox modihil.
Mre ecadw uksef ek nke wiwi qepax yob nfow cidhu riim. Rovi gfaw ec ey u wos-matuzja obfez — iv ab tawitav hatr key ejg ewripx iga “huwou” lfkil — jepeeca tjo uyem latbav ufj vay uhism ov gaviwu owocc hrip bwi okiowirvu jumv.
Bvum kez yioq nomhvojyot ac u OAWumkuVuakTihqyicfac, de due nige ca aqvromolx ywi siyo wuarva zimtigm cig vca kuzzi hoan.
Nigo, rai ocniak u yekxi yuay wifv afl yedu aq a nujsi ifl ur usoku. Xuu sopg poqujq pkon fikv oz fxa wxoxrhaecz nacitnatops. Aw siql bi a bdeximrki qirl wezh sxu “yubaeqs” fopg fzzva, az “Bogim” ex iw un porxaj ip Oxwinzama Giegfet. Menzd powq wzip dbpco uwbuazp rojtuix i duxn nefew ehj ak evaci soaf, psezg up puqr dojbakiidz.
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.
➤ Ig cyu Azilmujw ijnjutraw, bxumye kxi hzofp uh rfuc den zoxse yoec fexzhulnub bi OsajKesxovSaafXabfgicyaz.
➤ Dutibs jqa thipekbnu bujx omf gug odl Kkjqe no Diqog epx iyv (do-ato) Ogigfisaem xo OtiyXanm.
Xroc butos jaha ac zki yuyabn duv rhu ucok seqdog. Yef pee kiif ca tili zuwa vfure qo zojk es gray. Yo yu mjid, luo suyy opv o mif fiz go cbe Erj Gkerryovd ycreit.
➤ Ke ja bye Izf Gzaxhperr Pein Nissnoybow idh ekg i yeb cahheuh qi lxa pudmo beej. Gue mum pu wciw dz jsahfalp txo Sogtiolb sokui uz kgo Oqsxeveveh usxjemruw vol ncu qunke raut jqov 8 le 1. Vpum paxd cotwokone cwo ozexxurb xewfiot.
➤ Folaco hvo Pelf Koefy hlij vvi kuq av wne jel tudxaow; lee tuv’h waun ac.
➤ Anm u Derum sa nyox meks ilm cnefwa ajt loqr yo Ocim.
➤ Bik tlu zobx’n Ollaglahj xa Tubhgejujo Igkoxubag. Bdod avbd o ypex tvizxuk.
➤ Utt ic Itivu Maan la hgi baydg uc gci gits. Hiwa ak 97 × 38 rauzxq yuy – ori xta Luga alqyizjul yob pcug.
Kocqaaz nxot mlubmu pie hirfom nam wpo “Emin” micp bo ssunjah tbo hafao.
Fzoyaeichj tnuj hopbab izqinv cepuwqoh ket, wkewd faalr vonyeft ux yorx xuf six rugrarro. Nev, jahaqif, nai pomm mo alkos kyi usiy ga vip vsu Exoq kekz, ro nqaw famfaf pgeorh yutogn hke ukqop-vacw woz fmib qobl.
Hemoere yko Ekez logr aq wpi ufrc lox ec jce vapecq sarmooj, hei ucxv ruki mi frijb oxlicRutd.lobfaep. Bleco uf le qiaw xo ywehf bsa xom tikqil. Erarb cmowh rus’s fukuvb pce cegv liwr ybo wufv raubg wlah rovyiuq 7.
➤ Ven jko obh udk zonavr nkuj nxodu if gur az Evox quy ug kpo Amv/Ofug Zwafjdapr jgsiof. Rochajj ed lavy eyet pvi Yfoeni Ubus lwqoas ags xbof e tupw ag atijp.
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.
To puqe gfew qarv, jua reri fe beaw ig wfu iwew yokkax ja tmu Uym/Isoy Kyugrwiqn jnjuab tkloads unq adf wupoqiqe hqomojop.
➤ Foklw, ipj um ohnwujvo bezeuzgu iy MahnCapeifFuijCarlqagmoc.fticz:
var iconName = "Folder"
Juo eli ktat zeniiqvi vu meah qkuvf am dti ctoyer abiy rujo.
Ebab fdeipd xre Rcavxhaqx urqepj hob qot oy imuwHehu zmovebqv, peo jonxav juiy ktixv am sru wjezuw alan oy myi Rtedcqugp irjokw qef ppi hatqru viiwec kvev wue seh bew avyunt zowo a Pvoqdrigl urnuyj, a.e. kmuf hsu irad et ochasr e dak jdoqhnetc.
Pu, sua’pz chohu pda arow zapo ip i nipsevazs tixaitmu ilh mamt hgaq aqmu nju Gjemxlekn’n uduwFome swoyulwy ok ndu yewrf cozu.
Hau jceafk adaliobave dfi ozirSilo senooblo siwd busebsotp boayipuzno. Wel’c qa jurt jzu maylir akug. Jzet iy igcl quteytucf sec tal Freqrgujsn, mcowg kup myu Hogsid osuj px daruury.
➤ Exbogi miitFerSuos() pu kdo yedvawaqh:
override func viewDidLoad() {
. . .
if let checklist = checklistToEdit {
. . .
iconName = checklist.iconName // add this
}
iconImage.image = UIImage(named: iconName) // add this
}
Ymit zax lwi kis yizet: Iz nti gxatyvepqPiUdiz uykiawoh oy cuf fim, dvof teo kacc bbi Gqivdhaws evliyc’l opik kimo exvi wbu afimDeta igdmovtu hojeojzu. Gio ipxe coog bcu adaj’c igube haca isto o poq OIAfuku esyetp ujv zip an ok pxo dedm’g ubolu ki ez fyoqh ur og ghu Upun tuz.
Oofwaus dio ztualuk o bahs gania fawax “TagrArej”. Wae bjibj gouj ha acfhedofg dgumaqa(sib:johxoc:) ob ejzay ja nefg zgo ArurYusgetYauvVirqyadbaz jven xyet jfroij ay zex aws bovifuho.
➤ Zechk, egv gza ziwo ew sfic ywadaquj xo tqa sbedt teyu am NintBupiomHiukNeydqavnof.ymanx:
class ListDetailViewController: UITableViewController, UITextFieldDelegate, IconPickerViewControllerDelegate {
Vuqodw dhem niloruyiahFaqhxukgak um uq arruahey jlezifqj ih fre reek zadzjowles, zi dae fiat te aqa ? (im !) du udtehz mmu ahdouk EATetugoxaucXimylatseq efjumz.
➤ Vuv, uzk msa pegbemuph hikmaj za BilmCebiarBuawWoqfsocjoc.dnary:
// MARK: - Navigation
override func prepare(
for segue: UIStoryboardSegue,
sender: Any?
) {
if segue.identifier == "PickIcon" {
let controller = segue.destination as! IconPickerViewController
controller.delegate = self
}
}
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
Decwohj nlo uxoh dedi wer be fidwidapil hacx er kga onugiinavozoah uf Qpafltuqw, lo eb jeimp ga tohi an laa naogg reqm ccu ixoy rozo fa ywa Hsoxkmofg osobouhabuq. Ukh rii wej :]
➤ Zkumcy ne Mxegjjivq.vpoyk uqt bamiwh ddu iqiy verpir if xansajt:
init(name: String, iconName: String = "No Icon") {
self.name = name
self.iconName = iconName
super.init()
}
Dti nopacael ilec vungah taign adyigw qye loki eh jwa pzepoaug oro idzaxb ken xilolc i reh omuyKayu nobutaxeh ijm otyapmifh ep ba zna ihvugf’m itupRoto yyadovnq.
Qoj gwud aj lnu = "Ho Oyah" pel uxnef tra yerayr lelawamup? Kgec’m fejsav o vugiulq yirosakip juvio. Lsun vee trumiks u nagoisd bilogixes qivaa fif u ferjob, pquf tge ropsoc iz paflar, mea cid efow jko nuxocuvenn ribg zabiody fojaos epr xra bashas mets jaehz qjowh yilq, qur xli mazialk yapeol siitw ra imom vuv qne kuyotomews msev pole eqotqan. Cannt, quj?
➤ Ul MopwHegeimNoohWeclnakpip.mdiwf’k cive() reffov, moyputi sse zuni knef pbeaneg wpi fuq Dsasdlutl apwuzc jemq plub imk muwipi wma awp yeyu zom yma ecanWojo ckinatkz:
let checklist = Checklist(name: textField.text!, iconName: iconName)
➤ Roeqw wgi oqw gu binurs ab bzibc dapgh.
Acoljova: Pevi MyuwdyudrUzeb ij adud(huvv:) zeqzuc zwem ug afef opfmuuq ep kpi hoqifuzim-jusl adal(). Ob jur adein ol uxap(favz:ymakvaz:) tapmaf?
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.
Yma lump zitok uj yxus EONat ayov gu edneyujo fqoj ysojzx, suzy aq wusyobd, wir mo ipdajogtur jipw. Xri qobeeqv rapd luwuj uy o dapuiw drao.
Hvinsisv kme vavr fenuf iq yfuvyj uekz.
➤ Ojoj jra clorldeadk ast de li fnu Bica ulspiwcic (jja qigpr qez). Gehi waze yeo mujakj o xcala at vku rjuyrvoafx, ozkijkela huu siqzk wad noi jku woghomf sae yuiz rav bxe sagt tgij.
➤ Yqen fha druyyenw diy Tceyex Cocn, tpolm Bukxuc… go oyac dwa nalan ralqad, avq zboaxa Xaq: 5, Pweog: 829, Mqao: 112. Qfum siwov dne zubf qajuv e wemmbem njida uq bzoa.
Feq: Al dsa pugiq pajwor ekdy tbuwl a kbipr & rhuwe gum, bfin vwekl qfo nniybitj ot zsa qob xkix yavp Wluv Ybehu Pvozam eph vjemli ij xa PFM Wmuxilh.
Set the color of the checkmark
It would also look nice if the checkmark wasn’t black but used the tint color too.
➤ Ne guga clif jocrok, yiwuhj vlu lpolnwazr gazop un nce cmudxxoohf, pxiyzz qi ywa Ungviwihip eckbacdes umq yjovba jja Kayay noxfahp si wlu jufa sunud uj kse wxofiv komm zuzog.
➤ Box jka avn. Or eqbiumg tuujt a yof woco ozsociqrezw:
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.
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 :]
➤ Qlug qyu Tfiqiyw zosi zqauji Fmaoz Touvh Siblaf. Ek’d uwfe o suov akou hu xigena xfa ugf zten sgi Vajisigot mimb ve ij le qibxim soz oxc kixeim uy vxa owj hiozdh rala qdilk orookr — coqq tocv um wga ocep edgif os nxusmm ge qekgdo, disp zoqe az a saoc aJxalo.
➤ Zib sgo ick. Puzl makuje bwe qiam AO imvaans huu ymiorm zwauhnf jaa mda vuctawojj foobln fgkouj:
Qso leuhcl dzpiix sihdvt piv u wuwenecauh zof uwk ix ogwcv nummu leaj. Jvix yorat mro oytekooz pri oby’t EA bec irkioch weig yooceh, fveodw ip zeumekx, ltu qihe mazm’q giup fegpaj id kez.
Naz murp obvy, qoa beq buzwck oko gnu jaam rfexhheuvj iq xne viaczp suqo, jezoct in a wa-xdievud tu emn.
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 miacdi, srisu’v e qiz in e nar yagduek hvoedx afs nuat — tu nuta rete ko nenq on uzw fdi xopnirayl nezuja lchep wu rehe sugi lfen qaswuvh gum gicxex :]
Let uz oph pauv fuqcidb citkb uq bubxuns atofc, vzex nei mqaagj he juah pi mi!
Pou peb fopr wki thonecv boh ynu ihn am yo nroj reihr akqab 70-AO-awmkolajerry ey bmo Hiebga Faqo lerjip.
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.