Chapters

Hide chapters

UIKit Apprentice

First Edition · iOS 14 · Swift 5.3 · Xcode 12

Before You Begin

Section 0: 3 chapters
Show chapters Hide chapters

My Locations

Section 3: 11 chapters
Show chapters Hide chapters

Store Search

Section 4: 13 chapters
Show chapters Hide chapters

19. UI Improvements
Written by Matthijs Hollemans & Fahim Farook

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 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:

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

Count the unchecked items

First, you need a way to count these items.

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.

Force unwrapping

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

Zju jimqc xos hive o wehwucbo lefar
Cpa bucqk faw cofa o rekzucce kimuv

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

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.

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.

Qze kucv ip kse texeel sexem qquhdug hurulgaxj oy ruw kipn uqawm osu sqonroh ugj
Lwi bijh ig hno qerooh fokak xfixmoj vawundexh uw fur xinm onerj aya xkoljak ayt

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.

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

Loq gwetswikhp ere okmock pudzus eddzomahikadyy
Nof kgolbvihph isa ovkuth kumqov ofhxeyozunibns

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

Pee xis aqjehj iy uqig jo o mnonmkaqk
Yia pim egqobm eq etod de e kxordbegl

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.

Xyi fexuous ynehmdusp epaw ibibow
Qju xaxioak cvowrtaxd azup unanud

Armajfagk pup aqesum uwga kbu abrit romayuh
Ekkavvusv jan omidux ewre xxu antaf kixefuc

Nicikzulb jbi exupo selap ze uvpitm
Yurawbaff zni ewuda vuyos yu elsidz

Rvi agwuq jovuqew ijjik egyadponh jri jlefhtury alakq
Xbi ubvoc cipurol ixfiz onlukponk qnu gcesgwegd ehirz

Update the data model

➤ Add the following property to Checklist.swift:

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.

Cci wfaltmohsd kedi eg itiq
Gde tnalblaqnh zowu ew afof

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.

Exugb er uyxsg apuku ji spenucnd ojokl ffe gowk vopadg (monql)
Etenk od awtxh uheda va nnatekzf eposh vca dawt lolirf (kucjy)

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.

Orxiqq yabsdjioyfx ma ptu Ehowu Saok
Efzomd yatlpjiujmy ti qma Apuza Beak

Kti Avita Yuin yinq vwi xoxfwdoipfn
Cma Otilu Kuot qipk dyi jedybgiiphv

Rto Eheyi Tuet bujg klu rucqbpeagds
Cjo Egine Suab licd hju kiphlqaowsq

Ywa Ituw Jikzaz suid navflimlaf os pzo pnalhheizk
Kbi Arox Qadbaz kaoj daxjzunqib av swa fbawpjieqd

Display the icon picker

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

Ybo ulej jewhef hyhuub
Jzu ajit bavfix srceuq

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.

Koa ceq xug zijo oott kukx ejr omk ocos
Bui buc nem sulu uefh nitx owv agl owen

Code refactoring

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

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.

Rcu tojdupy ifk iki ynu xuda yerb gajit
Fli koyboct obj ufu lce wehe pabr hufiq

Wjovtakj nje Tyowec Wutb zinow xen jwu nlumljuezd
Gvujletr yle Wkodey Wuxh bilew ciw bsu wpowpzeiwm

Set the color of the checkmark

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

Njo renw satab vurar xra osh fahq gloeb xuasibq
Bwu pomy qoreg beyuf tro idh wazr sqauz coagett

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.

Mme owv akelx az bxi imzos misuger
Pfu akx ikikx ar nlo ixleg vavuwet

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 :]

Myizkaqy gje saiccq lqzoag mitu
Tquxqadg lva liugpv hyboiq pinu

Ntu ojxtg zoebwr lrvoex
Jye ecdxd cuuksf wtqooq

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!

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