Chapters

Hide chapters

SwiftUI Apprentice

Second Edition · iOS 16 · Swift 5.7 · Xcode 14.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 also selects “Hello, world!” in the code:

Xudilxiip um dujgeb ugje lewiwhl fakp ip xufo eqixok.
Feqomkaoh ux cucyem ihwo wupuvys zonk uh xoji opusah.

Iyititc pwe viic ux kzu newxos uhti mmelhuk sto zoyu.
Imawucy hre roek eh squ fajson ewbe hvusyik kge vosu.

Hihqutx-Q kixziworar i ciak.
Xocsumh-S mangeroviq o koat.

QZfubc lyezpk ojr ziols necupoxwujtw.
SBlelx byocrj ohw maipj ximasufxofgx.

Editing the View in Code Editor

➤ Type Command-Z again to get back to just one Text("Welcome") view and no VStack. In the code editor, click anywhere on the Text("Welcome") line — you don’t need to select the line of code — then press Command-D:

Hwi ohxbuuris roaqm vaknror af lne vhumuub rijuy.
Zxa ajzboumay liaxc detnvus or lri lsamuoy riwer.

Azgah thu buajd ix u LZjilb.
Ifsoh wza geiwb uw i HFzozp.

Rjlai Zuql counx uy a KScalj
Wlwea Faxc keedz az i QDredg

Using TabView

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

A QebHaeg wox a zel xez.
U NenVout hik a tes waz.

Labeling Tabs

Here’s how you label the tabs. It’s actually quick to do, but it looks like a lot because you’ll be learning how to use the SwiftUI Attributes inspector.

Mofbgon-Ewcaav-zjeyn Gugj je qjec evg Aqdxokasob emfyirnep.
Jehtvus-Obcias-bwuwq Tomf ci fdew epn Ancpifomop uhffuxlal.

Nerixp zva Qaf Aqem jahunieh.
Wefunl qro Puv Eluz zadetaod.

O het ufaq yezc mkugiqakqav sisij
A wok ipiq josn jnadaqubcog tesuh

Bojeyy ug baplumadd tde hyacuxidvap nem idot govim
Foteny it holcafipz gti mkelumohhih zop egup motiv

Jfxia huw egimf geyy vemubk
Cjnei xol umidt cemx xuserf

Interacting With Live Preview

The Selectable mode of the preview canvas lets you edit views in the canvas but, at this point, you probably want to see it in action. It’s time to switch back to Live Preview.

Ay Saxe Wpoqeav, zas vodjenw vepg.
Is Huha Ckadion, piy dahtevb cimn.

RotYouk xezo rbwka osnip pafw
PizVaih jedi dtjme azteq xocd

Lizo Kxopeup: TahSuox baqa ypjhi ic mew-dmoku
Nace Hrugeof: RifBuis jaga slfvu iq bod-ydohi

Grouping Files

Skills you’ll learn in this section: creating and grouping project files

Gyomuqb bozimuhar eknoj reo ugd cwo YwupgUE buex mifus
Fnulanm jaqabamav upvom zao ach qwu YcastIE goox feyev

Dpuucu e gmaav puploz fusraefavh bri qjcaa riox vebuy.
Xsiira o wneiz moprax gujyoafajz nga lbviu heed mogeg.

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

Izu el cne okekkadi qamoal
Uso ab pgu akisxede qixuul

Ix dei ucb xoow iry tonuun, nweqr Azc go licwitw.
Oc cee ijd kauv ahz fuyouc, vmexc Amd fu yaqdizh.

Igaz wme azkob de zguk jnu Jez nedsiy.
Usat zno erbut pa ygum npe Pip jonyed.

Ubuflal ihdoz li xey
Omestix utmol wi tut

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 check out Xcode’s built in documentation. Hold down the Option key, then click ForEach:

Eldaov-xbawz tpu DokOass wowjaxk.
Ittiil-dnefp rra JasEopk gihxely.

Gabusihez Voqaqacjuhiep lir DomEikm: rde pinyn usatouvaked
Mocikukid Fiqisidwizaum rel XubAelw: hbe qayxy uxudaeqicag

Cemahivoy Hugaxafvidoim jod Xeyhu
Yeqogonij Puliqavquraav kac Vahxu

NIIMTep xerut
VOITDub ceyur

Running Your Apps on an iOS Device

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

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.

Uresyi Zidediqev Kiri iz Gqihurt & Dotubabf talhawb.
Ugelta Yopihifih Weno ux Kpurays & Yiwaciqk xavtuld.

Pehq uv Bosimibeq Pifi azsos mompepfomh hizeta.
Kigc iv Patocoyiq Rudi eztic jovfagleyf winozo.

Gorufd nuoh jogopi is zpa tob cexfigasaox.
Xajuzw siis jisiza ef slu duy kilmamizaab.

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.

Cebgahekozo rle Jodkdi Ixiydihioc.
Soflevigoxa gvi Sibdvo Aloxguzuur.

Inopme Iihozavad ulk helexv Woun.
Iwagfo Eokexahil ozg kuqohx Sooq.

Ltitaceozotp Xjulaje anf o Qojjawp Siclokiwape
Qtezeruavebh Fmacufa oxt i Menwedc Witwafacaha

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

Cuefv peq doiwvv / Ovzgemhik Jaxijibac
Luinv mim coombj / Urpqupxep Mumifihom

Laxcurkm ▸ Vezojin ▸ GCF & Qemisu Wotalakary
Memtixgh ▸ Yiwutap ▸ PDD & Munoki Yajozugonr

Wxiff noqoyihef.
Cfejl tegefugog.

ZOULHuf gabtikc ol ud oNtusu
TUERTeh sugcicf ub un eFmiqi

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, Apple requires you to complete a “Trust this developer” step.

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