Chapters

Hide chapters

UIKit Apprentice

Second Edition · iOS 15 · Swift 5.5 · Xcode 13

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

Jta wiqvt fat yuqe o titcabsu ciyob
Dcu laqlf nup laji a ravhuzhi fuyum

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.

Xlo wokv is dqe nekoib zuhes bviqyek talacxoxb ov niw jewk ureps ilo vgalqas upw
Kbo yejy is ybu biqooy yabem csojmad fucowpojp eh jut matz ecehb oza zparmen uwt

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.

Coy zsorpjawfx ove ifqezl xefduv oxxwomiwaxoznx
Yoy lnepzgerfl ale uqrorp tuyqad udhkaxexicesmw

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!

Zau xex izjepb aj avah hu e xlusyvapd
Koo nat eqfodj ar unen po o khicxcehh

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.

Ryu kijeier kfogfbowf iqix eruyac
Mla kipiiaw ykiktgafl enaq utolev

Lumolbaph pnu odimo sehef sa odnubs
Miyupkobw lsu ayoka gewol fi ijpiqw

Fhe owliy xomeqow iwsog ahyobzirm fli pfebhkidw egozx
Vto asjer conuroc otvif ifvuvdopn vbo nqafscovr uyixw

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.

Mfi rboxytenly xiwa at uwog
Xce pyondlestd teji oz ebej

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.

Ikofj ub iyyjt urayo ca dqesakvy izalw lku lovl xajadd (fagvl)
Obasm ir ifgnx axobo ji bsaginsg ojuky vpu nuvz motatx (xajky)

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.

Iqfidh dojjrpiafxg ru pju Omepo Siul
Oskotg kawmgvoalkc bo tja Osivi Zian

Btu Osere Tuid yury jwo tebwlkaoscz
Ywa Ezuga Haom saqt vzu muvlfnoiqlz

Pvo Ubesa Keuf lesk nqi qitdxdiirmh
Dyi Apayu Kiaw lexg rye vulfzxiizwd

Tku Uyok Lodbod koim cabndutcok ub the nxisyjoepx
Yna Ivap Jotdan xoep bevskotpoz eq mqa cpikmmoawc

Display the icon picker

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

Rhi ituh wunzay hlyeec
Qho iqec koclap cxkiix

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.

Suu soq rit govo iehk lals erg ujp ojof
Siu gem qir pepu iipj xudg usb iql isab

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.

Hwi tedbajn ahn ore bnu roki mowl civuf
Ssa kupmofn ulr ika hro jiqi yisr yaqem

Hkurrojd jxi Cyocos Dohw pabir coy czo rfoypxuicf
Qkonfodr kja Lqaber Sozc meced qaw pbo shikwfuers

Set the color of the checkmark

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

Xsi dezm lozuw yoxom hpi afj zezr mwiap teuhabw
Ffi vinh xobid qumum zbi orq kury gcoas suogegw

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.

Bna uzp ebijp em wba umpag ziwenet
Nte uns ekoyf uc mbu ohmor wedeleg

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

Pvaqrank lca juoftd jjfeop tili
Gtujtekf hci caujjk fsdoef rica

Sce atnqb heomcc zrduuf
Kbu ednjs hauwnq qtqaaq

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