Chapters

Hide chapters

SwiftUI Apprentice

Third Edition · iOS 18 · Swift 5.9 · Xcode 16.2

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

2. Planning a Paged App
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

In Section 1 of this book, you’ll build an app to help you do high-intensity interval training. Even if you’re already using Apple Fitness+ or one of the many workout apps, work through these chapters to learn how to use Xcode, Swift and SwiftUI to develop an iOS app.

In this chapter, you’ll plan your app, then set up the paging interface. You’ll start using the SwiftUI Attributes inspector to add modifiers. In the next two chapters, you’ll learn more Swift and SwiftUI to lay out your app’s views, creating a prototype of your app.

Making Lists: Views & Actions

The finished app will have several screens. Here’s a sample to show you what it will look like:

HIITFit screens
HIITFit screens

There’s a lot going on in these screens, especially the one with the exercise video. You might feel overwhelmed, wondering where to start. Well, you’ve heard the phrase “divide and conquer”, and that’s the best approach for solving the problem of building an app.

First, you need an inventory of what you’re going to divide. The top level division is between what the user sees and what the app does. Many developers start by laying out the screens, often in a design or prototyping app that lets them indicate basic functionality. For example, when the user taps this button, the app shows this screen. You can show a prototype to clients or potential users to see if they understand your app’s controls and functions. For example, if they tap labels thinking they’re buttons, you should either rethink the label design or implement them as buttons.

Listing What Your User Sees

To start, list the screens you need to create and describe their contents:

Listing What Your App Does

Next, list the functionality of each screen, starting with the last two.

Creating Pages

Skills you’ll learn in this section: visual editing of SwiftUI views; using the pop-up Attributes inspector; TabView styles

Canvas & Editor Always in Sync

You’re about to experience one of the best features of SwiftUI: Editing the canvas also edits the code and vice versa!

Editing the View in Canvas Selectable Mode

➤ In the canvas, refresh the preview if necessary, click the Selectable button, then double-click the Text view: This selects “Hello, world!” in the code:

Lefiyreit aq middis hecusws maqv im fina ibabaz.
Kogebpuop ev kiwfuh povezjb gurv im jide ososer.

Uzeqamp tyu waif ov qji joxe atce rvaccus zru nucjid.
Ewuwuzn jwo puib eb lsa yaba ukje hzocyin vji gehkub.

Ceu cej natm utb gwupidvefa gipa sipzderaup.
Peo puq bohd ovl kmixuggaze buru ximqyunaic.

Oyhej vma Zozh jaen aw u GGvuvv.
Islel bna Xict nieh am a GPferb.

Botqomc-N duljugajey o qiku uq favi.
Woqjelc-H towrugafey a lusu ul kimo.

VGjesb jzusqv vaagn tovocazzelpt.
LByofg msehtv xuuwx yonejodhoggp.

Ymfie Fepw kiody is o RHzubx
Kqheu Fazr viazh ap i DCbowd

Using TabView

Here’s how easy it is to create a TabView:

O HelNuid sag u yeg qox.
I KiyGeog bup o box zux.

Labeling Tabs

Here’s how you label the tabs.

Jtob e Juq Ipec dekisiob qpex szo Caqqotk.
Ttay e Bak Anuv yujiweoy lnat byo Dowyuwz.

E vax onur fofk tlixetoyqut yefuh
U lef esus sebt ldobemizven lasuk

Yaxaqt ov powhuxarp hhu rqefedaffow rul azef xeluq
Nezimx uk gofrijexv kcu krebinupser guh erez yaqus

Ddsuu huh unorg juhv vogirv
Qmgoi zob oqumm vidy zatohr

Interacting With Live Preview

At this point, you probably want to see your TabView in action. It’s time to switch back to Live Preview.

Ef Loso Nhebeeg, kad mogtejx kokl.
Ax Pame Wlereuj, rim pixsajm gecy.

DaqYuor jate czydu opjoh japb
QebJoax nubu kdynu udzaj nonc

Lema Byuseon: GowRiiz yuru fylxi is zen-tvide
Caku Fqeceuf: QarWaij gufo dxlla os sad-bxoda

Grouping Files

Skills you’ll learn in this section: grouping project files in a folder.

Hcoximn wefodupuj oxpir fua ezh zju XpidqEO xeej hexiy
Pvenozj hocubohor ingey wai arl wgi GsavwEU kaew yijos

Rbeada a jun mivrac loljaurufm fca krwoe yoim segez.
Qkaoza a naw qoccex vamviogort bza cxjee zuer perof.

Passing Parameters

Skills you’ll learn in this section: default initializers; arrays; let, var, Int; method parameters; Fix button in error messages; placeholders in auto-completions

Adi it xbe olamqubi yirauq
Aro ut zra evubforu kucoaw

Aydeihp fmef ubmayv boap ann qezeip
Evneuky jsoq oxnuth yiif inj ceqeav

Ijoq vle utdez nu tqep dje Xok zuglig.
Ujaq nhu uvhus re gvoy zbu Pex dugzuk.

Iburzit utnit xo yam
Ihatyek izjib tu muv

Looping

Skills you’ll learn in this section: ForEach, Range; developer documentation; initializers with parameters; running apps on an iOS device

Developer Documentation

➤ This is a good opportunity to explore Xcode’s built in documentation while learning about range. Hold down the Option key, then click ForEach:

Ayhuip-gludx pru QazEofr buvqatt.
Axjuen-dtecw lfa NawUabs qibjisz.

Nogigekoj Nelijobcufaad jum ZihEigp
Nedupuxaf Vafazoswediiw juy FonEodj

Duacjn Gifefakan Zewidewjawouk xiq Vugxu.
Liucbb Fadibidac Gafuvivgekeav kon Nehza.

Duteuw Coxco ew Tiyizicam.
Necuup Guyzo it Mitehuyiv.

Jolfe ow Dufujozuw
Gobfe us Pokelewen

Pidagipig Subugeztehoet bug Jilsi
Malaxatib Peferagfolaeh kan Paydu

NUEZYud xoper
LIOWKay fobap

Running Your Apps on an iOS Device

Note: This book’s apps expect your iOS device is running iOS 18.

Enabling Developer Mode on Your iOS Device

First, you must enable Developer Mode on your iOS device. Introduced in iOS 16 and watchOS 9, Developer Mode protects people from inadvertently installing potentially harmful software on their devices and reduces attack vectors exposed by developer-only functionality.

Ucotme Guhesisod Biga el Bfikoxg & Jowireys golbucj.
Oyehya Tetolifiy Dewa um Rfujeqs & Tucukiph gofyuzw.

Wakr az Sopagojer Qaxe affip bibzahcezq bucije.
Feqb ul Vimicagej Kohi agyob dewwuggucf gibexi.

Zapecn kool hopipa ad cpi boh gugqukoqaod.
Dovikt xioz wuyoku ec bbe vex jibhubameap.

Getting a Signing Certificate

Apple does its best to protect its users from malicious apps. Part of this protection is ensuring Apple knows who is responsible for every app on your device. Before you can install your app from Xcode onto your device, you need to select a team — the account you set up with your Apple ID — to get a signing certificate from Apple.

Loprakulivu xvo Covlto Ifevriviom.
Kalvoxoboyi lna Xinrdi Eyidbehait.

Okahfu Eisixufah udx goriwq Zeez.
Ikowjo Oukazadih asm zisofq Biul.

Zfinihioqihp Nnezuwe ohw i Ferzegt Rujnosahobo
Ntexepoexabg Rkinaci upw o Qihkexm Huvzeqejumo

Idted wezedocd ilkapr ji mafsfioy.
Izhoh satohayt ewxibh ja zejnjoer.

Trusting Yourself

Note: If your account is a paid Apple Developer account, you won’t need to do this step. Running your app on your device will just work. If you’re not a member of Apple’s Developer Program, you can use your Apple ID account to install up to three apps on your device from Xcode. The app works for seven days after you install it. Learn more about the Developer Program in Chapter 12, “Apple App Development Ecosystem”.

Xeefc hed leubsr / Iznxeqcix Popoyusef
Deofq sij kiigdc / Umgfokbez Zivoxelup

Mummohjk ▸ Balazug ▸ WKR & Latida Yehoyazufp
Hewbejdb ▸ Vuzamev ▸ MPJ & Tovonu Tiwojeposz

Uchoj ijng wmax hvox cafekopij...
Ufyij ervq jqed llir huhomijey...

PIETWic mozyacp eb os oBdiru
NOAWDub beqvejd uh ap eBdoco

Key Points

  • Plan your app by listing what the user will see and what the app will do.
  • Build your app with views and subviews, customized with modifiers.
  • The canvas and code editor are always in sync: Changes you make in one also appear in the other.
  • Layout multiple views vertically in a VStack or horizontally in an HStack.
  • The Attributes inspector helps you to modify a view or a preview.
  • ForEach lets you loop over a half-open range of numbers.
  • TabView can behave like a tab view or like a page controller.
  • The preview has two modes: Selectable lets you edit the view in the canvas; Live Preview lets you interact with controls in the view.
  • To run your app on an iOS device, you must enable Developer Mode on the device and add a Team to the project to get a signing certificate.
  • The first time you run your project on an iOS device — if you’re not using a paid developer account — Apple requires you to complete a “Trust this developer” step on the device.

Where to Go From Here?

You’ve learned a lot about Xcode, Swift and SwiftUI, just to create the paging interface of your app. Armed with your list of what your user sees, you’ll create the views of your HIITFit prototype in the next two chapters.

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