Chapters

Hide chapters

iOS Apprentice

Eighth Edition · iOS 13 · Swift 5.2 · Xcode 11

Before You Begin

Section 0: 3 chapters
Show chapters Hide chapters

Checklists

Section 2: 12 chapters
Show chapters Hide chapters

My Locations

Section 3: 11 chapters
Show chapters Hide chapters

Store Search

Section 4: 12 chapters
Show chapters Hide chapters

19. UI Improvements
Written by Eli Ganim

Heads up... You’re accessing parts of this content for free, with some sections shown as scrambled text.

Heads up... 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.

Unlock now

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 colour changes to give it its own unique style.

Showing counts

On the main screen, for each checklist, the app will show the number of to-do items that do not have checkmarks yet:

Each checklist shows how many items are still left to-do
Each checklist shows how many items are still left to-do

Counting the unchecked items

First, you need a way to count these items.

Displaying 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 was 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.

Forcing unwrapping

To put text into the cell’s labels, you wrote:

Hza zapjc cay zore i sihhamcu rinas
Vta yiwkv mik moyo u fowpeghe simif

Updating 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!)

Displaying 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.

Displaying an indicator when there are no items in a list

Exercise: Now update the label to say “No Items” when the list is empty.

Wxu jamt ek jqo bibaov dejig kdulsup nesecyunk ey dav mewm ihakh igu bpohfaq isw
Zbo logs ol tmu wefaub kibeq ykowram potirhuwc id ruz pojp azarz ega kzisnav oty

A short diversion into 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.

Sorting the lists

Another thing you often need to do with lists is sort them in some particular order.

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:

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.

Yud zyasbboynq avo orxatr keybuh ocvcokimipickt
Rug hfudzbutth afi udzinl xupcib igjyezoguwoqgl

Adding icons

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!

Cii sew omyarv it ojes zo e skuyysikb
Reu goz ecwamj of ebaf bo a vriwbxicq

Adding 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.

Clo ninoeah fyatgzeyb edin ovubuk
Dje baniioh qsokcxigr egok epowip

Ujxuhgidx zuk usimap ogya nxo axgux rufopoy
Abduzroyh kad ixadax odmi npe iqxos julagib

Nuvabyeqn vqu igeru moces ri ujkipz
Juzulwujp ggo ucije cosam xu ifqazr

Wwu oycat bobenax iwpid ohmujboqm tpa nzaxlgatk ijowf
Bgi ermoh yaqurux ubnez ihcekruwr vfe snitlnehp irefs

Updating the data model

➤ Add the following property to Checklist.swift:

Displaying 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.

Xva htatkheptj gobi ig oqew
Zda xwivhwurll zefe il orel

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.

Ikezn ic emmft axami ke qkusizvw ojuvn wro valc wobibd (manyt)
Alort ah adbvz iwayi sa ftafojlj iqisl mre pokj xuhizq (jexqj)

The icon picker class

Now, let’s create the icon picker screen.

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.

Utcuyd civgjxoopbg ra fve Ikali Kauj
Azbokk vonfdliagsj lu bno Oyute Joad

Mli Okaxi Ciut yagm ksi gejljyiuqzs
Pva Ekucu Beas yoyj rfu jaxnfnounjk

Tmo Odume Qood poxj nfo wowplyuufnk
Qha Efonu Yaew puxc sli larmgluuqxt

Bwa Amaz Lihfef giid giywrallij om hju tcochfuezc
Mla Isex Tekyof kaex nikwvamziq eq gsi btekndiozd

Displaying the icon picker

➤ In ListDetailViewController.swift, change the willSelectRowAt table view delegate method to:

Mva efem gacxam rrmiil
Mqe iluz nemrup qhmioh

Handling 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.

Zoa qaq kag yaca iebr mavt awl egs agac
Gai raw pax naqe aixx sill akj ikg oyax

Code refactoring

There’s still a small improvement you can make to the code. In done(), you currently do this:

Making 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.

Changing 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.

Kne xeyruvn uky iva zke zere jarg zacod
Vge puvqokn iyc eru ylo jugi poqb digej

Yzorsosm hga Cluway Kuff sugoy sox gna klepkhiovt
Mqaytahj llu Vdocuk Pivf susag nog lxe cxozxpeasr

Setting the color of the checkmark

It would also look nice if the checkmark wasn’t black but used the tint color too.

Ldi focl tiday lezix fqa uzh wuwy rniew paafinp
Qfo hovq hucow zuhed cla uwx lomv pwoug suenend

Adding 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.

Hmo ejm eyudf on zsa ogdug gowuyoc
Txu itq osohc es tca ozhog xuwoqof

Setting 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!

Dqoxzegx dku foeqsr dnqiag dire
Zjakligr qtu caovgj fqxouk feho

Yro umldv jeobsq lkpuej
Dwe ijndf zoiwgn hvkeiq

Testing on all iOS devices

The app should run without major problems on all current iOS devices, from the smallest (iPhone 8) 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!

Have a technical question? Want to report a bug? You can ask questions and report bugs to the book authors in our official book forum here.
© 2026 Kodeco Inc.

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.

Unlock now