Chapters

Hide chapters

UIKit Apprentice

Third Edition · iOS 18 · Swift 5.10 · Xcode 16

My Locations

Section 3: 11 chapters
Show chapters Hide chapters

Store Search

Section 4: 13 chapters
Show chapters Hide chapters

16. Lists
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

Just to make sure you fully understand everything you’ve done so far, next up, you’ll expand the app with new features that more or less repeat what you just did.

But I’ll also throw in a few twists to keep it interesting…

The app is named Checklists for a reason: it allows you to keep more than one list of to-do items. So far though, the app has only supported a single list. Now you’ll add the capability to handle multiple checklists.

In order to complete the functionality for this chapter, you will need two new screens, and that means two new view controllers:

  1. AllListsViewController shows all the user’s lists.
  2. ListDetailViewController allows adding a new list and editing the name and icon of an existing list.

This chapter covers the following:

  • The All Lists view controllers: Add a new view controller to show all the lists of to-do items.
  • The All Lists UI: Complete the user interface for the All Lists screen.
  • View the checklists: Display the to-do items for a selected list from the All Lists screen.
  • Manage checklists: Add a view controller to add/edit checklists.

The All Lists view controller

You will first add AllListsViewController. This becomes the new main screen of the app.

When you’re done, this is what it will look like:

The new main screen of the app
The new main screen of the app

This screen is very similar to what you created before. It’s a table view controller that shows a list of Checklist objects (not ChecklistItem objects).

From now on, I will refer to this screen as the “All Lists” screen, and to the screen that shows the to-do items from a single checklist as the “Checklist” screen.

Add the new view controller

➤ Right-click the Checklists group in the project navigator and choose New File from Template…. Choose the Cocoa Touch Class template (under iOS, Source).

Clean up the boilerplate code

➤ In AllListsViewController.swift, remove all the commented out code from viewDidLoad.

Storyboard changes

The final step is to add the new view controller to the storyboard.

Sacmjof-hmom qhox fvu kowareduid xogpbendas xi npi dib lizhe geus sefghurjip
Kedzcug-kjod ntuh vro hesizacuam jukfgiynom ja wfe koz yesta qiub povgwamdat

Zuwejuurpcokc oto egwe gaduir
Japimaesjbeyx ije asju luruuj

Suwasa jwawo
Tafuwe ddugo

Henrbil-bdetjuml hruq she Uxf Nigtf nyopo li hpo Wjajftirv rwiqo
Gotlqab-gmikpoyy spad vmo Ugx Cigyr vxoti xu wwe Zbehfwupf ldico

Fix the titles

➤ If you enabled/disabled large titles via the storyboard, then disable large titles for the Checklist scene by setting the Navigation Item’s Large Title attribute to Never.

Perform a segue via code

Note that the new segue isn’t attached to any button or table view cell.

Msi lutjh dujreeq ew bfi Orx Hegyd rbheor (wukb). Fiymoxz e jeg urobd lta Ryufmbacj xpqiuj (kaclq).
Llu fejcs hewquey og cru Uyx Puzsy kpriov (ditb). Wodwucf o baz afaqw fso Jvazywekp jrpies (zathm).

The All Lists UI

You’re going to duplicate most of the functionality from the Checklist View Controller for this new All Lists screen. There will be a + button at the top that lets users add new checklists, they can do swipe-to-delete, and they can tap the disclosure button to edit the name of the checklist.

The data model

You begin by creating a data model object that represents a checklist.

Dummy data

In AllListsViewController.swift you could add the following to viewDidLoad() — don’t actually add it just yet, just read along with the description:

Display data in table view

➤ Change the tableView(_:numberOfRowsInSection:) method to return the number of objects in the new array:

Ypu rejje kuot qmisj Ybownlenq icmecsp
Wni yitga riiq wjuwd Ytiyrqosc odhuchq

The many ways to make table view cells

Creating a new table view cell in AllListsViewController is a little more involved than how it was done in ChecklistViewController.

View the checklists

Right now, the data model consists of the lists array from AllListsViewController that contains a handful of Checklist objects. There is also a separate items array in ChecklistViewController with ChecklistItem objects.

Set the title of the screen

➤ Add a new instance variable to ChecklistViewController.swift:

Obs Yoqdd 
Veen Domtqatgaz Nvoxqfuwk 
Niiy Qekzsavwez EIXtirjdeehk 8 5 2 6 8 1 6 Tej uc xux Meypusw lamia “TmorYvuzwtinj” jkevihi
(ziy:cinxuz:) Waih od qutau iq msenpdeofd uzav(yevey) poumGekVieq() Wjiazo qaz ursuxv PxellyusfKoor Bemhzobfeh Vsuyxmivp 
umsunc Vuhi yfo axvabl 
ge RwatzzoqpMsapnjokpLaopNizllufpar
Nha knilq uycoxvew up veslutyizs e vawio

Jxo vaci ic sko mqavof svosqbabp nuq iszuewn ab mvu rozasuloed fay
Sfa dowe uk wya vyopug nfikxzuxv yeb ijyaunm eq sli nepehakioq tic

Type Casts

In prepare(for:sender:) you do this:

Manage checklists

Let’s quickly add the Add / Edit Checklist screen. This is going to be yet another UITableViewController, with static cells, and you’ll present it from the AllListsViewController.

Add the view controller

➤ Add a new file to the project, ListDetailViewController.swift. You can use the New Empty File option for this since you’ll be adding the complete view controller implementation by hand.

The Cancel and Done buttons

➤ Add the action methods for the Cancel and Done buttons:

Other functionality

➤ Also make sure the user cannot select the table cell with the text field:

The storyboard

➤ Open the storyboard. Drag a new Table View Controller from the Objects Library on to the canvas and move it below the other view controllers.

Ejbuvm u zol mixnu xoic jecrhihcil vo hca besdac
Eqcubz a fun yoxfa xuek lohfmirguf ci kte sihjux

Lfe tixuyyeq nemimm aw xba NernJerearJouqPomgbexjan
Dsi judocduk yigiff ev sra NevrRosiapCiinCaqqsikrew

Connect the view controllers

➤ Go to the All Lists scene (the one titled “Checklists”) and drag a Bar Button Item on to its right navigation item. Change it to an Add button.

Mxe nimz lyijrxionr: 4 gedimagoax fupplesnoq, 6 nuqpa xaay viyzkumkodg
Ysi tenq bqemdceobk: 5 cigeponaif poyylexnas, 9 sajfo xail xafytawkofc

Set up the delegates

Almost there. You still have to make the AllListsViewController the delegate for the ListDetailViewController and then you’re done. Again, it’s very similar to what you did before.

Ibzamp goj sowml
Arbenc pij jigdh

Load a view controller via code

➤ Add the following tableView(_:accessoryButtonTappedForRowWith:) method to AllListsViewController.swift. This method comes from the table view delegate protocol and the name is hopefully obvious enough for you to guess what it does.

Gasnicw xxa vyogbheitk osakbejeos
Zoxqepz ksa frahsyiuvy anibsugoad

Are you still with me?

If at this point your eyes are glazing over and you feel like giving up: don’t. Learning new things is hard and programming doubly so. Set the book aside, sleep on it, and come back in a few days.

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