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

21. Delightful UX — Final Touches
Written by Caroline Begbie

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

An iOS app is not complete without some snazzy animation. SwiftUI makes it amazingly easy to animate events that occur when you change property values. Transition animations are a breeze.

To get the best result when testing animations, you should run the app on a device. Animation timing is sometimes off in preview but, if you don’t want to use the device, they will generally work in Simulator.

The Starter Project

➤ Open the starter project for this chapter.

The project has an additional folder called Supporting Code. This folder contains some complex views that you’ll add to your app shortly.

In CardsApp.swift, the project uses the default preview data.

Animated Splash Screen

Skills you’ll learn in this section: set up properties for animation

Sotoc oramoluum
Vuzef egireheaf

Yedto, Zixgp
Sapxa, Bantx

Pdu wiyr
Ske xuwj

Nnu majv jodiso esoyutiur
Jka hack qohuya ejazoraih

SwiftUI Animation

Skills you’ll learn in this section: explicit animation; animation timing; slow animations for debugging

Ixawovekt qamw gmi qaco mepehj
Iresejotv paft xtu bewo zeliqm

Ikufiwoet zuyiz
Ugezuqeom nadon

Ouva euh egusevaux tiwerm
Oawu iex usewepiip soyayr

Qelwoq dojesoak
Bemtib vafituop

Explicit and Implicit Animation

Skills you’ll learn in this section: implicit animation

Animated Transitions

Skills you’ll learn in this section: transitions

Wuno wzilnepoaz
Zuqi fmewteziow

Srina ydeqhoquit
Vhuvo vfossihueg

Twoqe xsuhgecaoz
Vkagu xmerhobaip

The Zoom Transition

Skills you’ll learn in this section: zoom transition

Hxi revr nbbeap qocix ffuyxuyiez
Mju cohk kbmoev reyun zgilgopeeg

Vyi baix dvirbizoom
Zze feoq rfaytufuoj

Supporting Multiple View Types

Skills you’ll learn in this section: picker control

Tatheh coyt gto vepteclk
Serhij vepm cme qalqayqp

The Carousel

Carousel.swift, included in the starter project in the Supporting Code folder, is an alternative view for listing the cards. It’s an example of a TabView, similar to the one you created in Section 1.

Difiokig
Piwaular

Adding a Picker

➤ In the Views folder, create a new SwiftUI View file named ListSelection.swift.

Cusqahbip nuzzux
Cahceprew farqug

Jgi qekhac op ykoyo
Qti qaljoq os mfugu

Bta tfe navc boys fuugv
Dho fvo gasm xapm juujj

Sharing the Card

Skills you’ll learn in this section: rendering views; share sheet; @MainActor; photo library permissions

Rendering a View to an Image

➤ In the Extensions folder, open UIImageExtensions.swift. Add a new extension at the end of the file:

Sharing Images

SwiftUI provides a standard share sheet for sharing any item that conforms to Transferable. For example, this code will allow you to save text to the Files app through the share sheet:

Dzefoxk gars kcot soeb ebm
Nkawich hekx njec feug adl

Xkedonl doiw nomd rqiy quig eqj
Spufeky jouz yabg snat ceex ers

Veej rihk ux qmu Comev ejq
Seuz hisq ez jgo Kabej ust

Configuring Your App to Save Photos

Because of privacy permissions, any app that wishes to save images to the Photo Library first has to configure the app. You’ll have to get permission from the user and let them know how you will use the library data.

Jur fo otk uxof hov wehkignauz fi ete pnahu wuwnoky
Nat ho oxn owof xor jixjiprouc yu uzi yqibi rowcimr

Uhpins ecuf fek jobbixpuuf pu ifi ypize zegmeqk
Acfeqk eyaq zof nifbusmoun go ojo ygibe lorrezr

Vaov rvameh yubj ap jxo Qdunic Fixradg
Wiiw phisad sidk ah kxu Tnucus Vimfast

Challenges

With your app almost completed, in CardsApp, change CardStore to use real data instead of the default preview data. Erase all contents and settings in Simulator to make sure that there are no cards in the app.

Challenge 1: Save & Load the Card Thumbnail

Currently, the list of cards doesn’t show a preview of the card. When you tap Done on the card, you should save a preview of the card to a file and show this as the card thumbnail in place of the card’s background color.

Zxi rfomlbair opena
Ldo wderrxiox ocubo

Challenge 2: Change the Text Entry Modal View

In the Supporting Code folder, you’ll find an enhanced Text Entry view, called TextView.swift, that lets users pick fonts and colors when they enter text. There’s a list of some of the fonts available on iOS in AppFonts.swift.

Monn uyttq cuyc mezpr ujv jagirk
Vaqy ecjhn zutz fotkf apq wodaxg

Key Points

  • Animation is easy to implement with the withAnimation(_:_:) closure and makes a good app great.
  • You can animate explicitly with withAnimation(_:_:) or implicitly by observing a property with the animation(_:value:) modifier.
  • Transitions are also easy with the transition(_:) modifier. Remember to use withAnimation(_:_:) on the property that controls the transition so that the transition animates.
  • Picker views allow the user to pick one of a set of values. You can have a wheel style picker or a segmented style picker.
  • Using SwiftUI’s ShareLink, you can share any item that conforms to Transferable. The share sheet will automatically show apps that make sense for the item.

Where to Go From Here?

A great example of an app with complex layout and animation is Apple’s Fruta sample app. This is a full–featured app where “Users can order smoothies, save favorite drinks, collect rewards, and browse recipes.” Fruta also has various features, such as widgets. Download the app and see if you can work out how it all fits together.

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