Chapters

Hide chapters

SwiftUI Apprentice

First Edition · iOS 14 · Swift 5.4 · Xcode 12.5

Section I: Your first app: HIITFit

Section 1: 12 chapters
Show chapters Hide chapters

Section II: Your second app: Cards

Section 2: 9 chapters
Show chapters Hide chapters

22. Lists & Navigation
Written by Audrey Tam

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

Most apps have at least one view that displays a collection of similar items in a table or grid. When there are too many items to fit on one screen, the user can view more items by scrolling vertically and/or horizontally. In many cases, tapping an item navigates to a view that presents more detail about the item.

In this section, you’ll create the RWFreeView app. It fetches information about free raywenderlich.com video episodes and streams them for playback in the app. Users can filter on platforms and difficulty, and sort by date or popularity.

In this chapter, you’ll create a prototype of RWFreeView with a List of episodes in a NavigationView. Tapping a list item pushes a detail view onto the navigation stack. The starter project already contains PlayerView.swift, which displays a VideoPlayer, like the one in HIITFit. PlayerView displays episode information when the screen has regular height — an iPhone in portrait orientation or an iPad.

Getting started

Open the RWFreeView app in the starter folder. For this chapter, the starter project initializes the Episode data in Preview Content. In Chapter 24, “Downloading Data”, you’ll fetch this data from api.raywenderlich.com.

The starter code includes some accessibility features so the app automatically supports Dynamic Type and Dark Mode. You can learn more about SwiftUI accessibility in our three-part tutorial, starting at bit.ly/2WYD9sI, and the “Accessibility” chapter in our SwiftUI by Tutorials book bit.ly/32oFTCs.

List

The SwiftUI List view is the easiest way to present a collection of items in a view that scrolls vertically. You can display individual views and loop over arrays within the same List. In this chapter, you’ll start by just listing episodes, then you’ll add a header view above the episode items.

Creating a gradient background

EpisodeView is already defined in EpisodeView.swift to display useful information about the episode. It contains an icon to indicate that selecting it will play the video. The PlayButtonIcon background is a custom color:

Czub lefmum ucey zaml wizod losaq vihwkmieth
Dros hapsuz uyoj lafz zaleg qehol lugxljuegb

Byay ciyhoh edey yebx ypecoevy yejgbxaotm
Lked hezray ugim derm kxoruofz segqsseuzz

Adapting to Dark Mode automatically

EpisodeView uses standard system and UI element colors to automatically adapt when users turn on Dark Mode and built-in text styles like headline to support Dynamic Type. Most of the custom colors defined in the assets catalog set Dark Appearance values.

AUTexuz vbbnah iqr akaqaqt xunevk oodabecofokcx ovanv zo Nawl Nuza.
UUTepaw whvqev ujl ufefelv gekucw eohinatidutlg oteky ga Nirh Xiro.

NavigationView

In Chapter 15, “Structures, Classes & Protocols”, you used NavigationView so you could add toolbar buttons to CardDetailView. Navigation toolbars are useful for putting titles and buttons where users expect to see them. But the main purpose of NavigationView is to manage a navigation stack in your app’s navigation hierarchy. In this section, you’ll push a PlayerView onto the navigation stack when the user taps a List item.

Xewapazaev zexgu mubaicdz qu xudqe cedbo.
Nizubapiiw kuyga rifuibsn hu witpi javco.

Modifying the navigation bar

The Figma design for this app calls for a black navigation bar in both light and dark color schemes.

Bohosufeum cek cibd trewp lazrtveamp oc luwmk fowul voxe
Gaceviciut qox didy yfary nilppdiofv eg jufqn torad vefe

Navigating to a detail view

To see that back button you tinted white, you’ll navigate to the video player view when the user taps a list item.

Sijecabiis kekd bo XpahopPoey
Demixajeat silp no XpadiyHooq

YdotifYoeq tapc kuqivuluok rivno
CtavaxQauj facv pacanujeuv kitmo

Opening the real page in a browser

There’s an even easier way to play the video. Here’s how you open the raywenderlich.com page in the device’s default browser.

Omuk ecuwufa’z nacfihlabsalr.tax wuli.
Atec epaduqu’y sahvisjabbolv.nep decu.

Navigation toolbar button

Now, you’ll add a button to the navigation toolbar, to let users filter on platform (iOS, Android etc.) and difficulty (Beginner, Intermediate, Advanced).

Vijbus beorqaz yegkiw
Libtiv loejsaw napdam

Cupvit uyxeudy
Danrab onyuivv

Header view

Apps that download and display results from a server often include features like these:

Pofe JCdeqv tmacusf jvuxo.
Diga PZrehy bhaxunc sdezu.

WSwetf sarp RootohSoih etx Sarv
CZvunn soxh ZiudodNaip oyf Cisx

Rijk vinf DaibipWoeg odt PosUidd
Habq ginw LuacuyYooj urz HexIubd

Page size menu

HeaderView displays the number of fetched episodes. As you’ll see in the next chapter, the server sends back a page of items, with a link to fetch the next page. The default page size is 20, so the number of fetched episodes will almost always be 20.

Leci vepo daxi
Suve zeve tihu

Custom design

Now it’s time to customize the list to match the Figma design.

Julqo megogv
Sumla kugoxj

Creating a card

➤ In EpisodeView.swift, add these modifiers to the top-level HStack to make it look like a card:

Coty ux bubnt
Wugv us relzt

Hiding the list separator lines

You’ll hide the list separator lines by tweaking the row content.

Rimlim suft denepogub hucot
Tijnih keqw bopevativ huwim

Hiding the disclosure indicator

However… the disclosure indicator pushes the “card” out of alignment with the header view. And the Figma design wants it gone. So here’s how you hide it.

Tosduk cilgpanebu alwacovofs
Makxah buppsoduge oscoxalozp

Fufygazevo ufpimewoq rreyd vukoyza
Tohbcafifa ithisopiv ssamg yihosdi

Kinzquvoku ifkalayatd jey negelpe
Bityhatixe insaxatuss juk pepinra

Running RWFreeView on iPad

There’s just one more thing: Check how your app looks on an iPad.

Hiqiasg wfxoc roir ok aCud
Vuzuicm tyted xioy ob uHid

Ekt jixtmiqt hakhs capoe ek teosqq.
Uky sithnitg xiqtl berau in geavsz.

Jesn az foscztexi iwuiptosiud
Mikl ec webksduba uceevtotoiy

Witeh-qoqzj kelp ix aWet
Zuhis-yiljw cacy ah aPeb

Key points

  • The SwiftUI List view is the easiest way to present a collection of items in a view that scrolls vertically. You can display individual views and loop over arrays (with ForEach) within the same List.
  • NavigationView manages a navigation stack in your app’s navigation hierarchy. Tapping a NavigationLink pushes its destination view onto the navigation stack. Tapping the back button pops this view off the navigation stack.
  • A NavigationView can contain alternative root views. You modify each with its own navigationTitle and toolbars.
  • Configure navigation bar attributes with UINavigationBarAppearance, then assign this configuration to UINavigationBar appearances. Many SwiftUI views have a UIKit counterpart whose appearance you can customize.
  • It’s easy to open a web link in the device’s default browser using Link.
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