SwiftUI + xcode 12

SwiftUI | Action Sheet

Let’s create an ActionSheet with different options using SwiftUI

Sullivan De Carli
Swift Productions

--

SwiftUI logo with an iPhone displaying an Action Sheet

Difficulty: Beginner | Easy | Normal | Challenging

Environment : Xcode 12 & SwiftUI

Create a new project

Xcode > New Project > App Template > Name it ActionSheet> SwiftUI App Life Cycle & Interface.

Xcode > New Project

Add the ActionSheet Modifier

Go to your ContentView.swift file and add this State variable:

We will use the State variable to show/hide the ActionSheet, then replace the current Text with the following:

And add the ActionSheet Modifier right below:

This ActionSheet is composed by 3 options, each one open a different URL and there is also a cancel button to close it.

Run your project 🚀

Run your Xcode project and click on the Text, your ActionSheet is there!

Xcode running with the simulator
Xcode with simulator running

Thanks for reading! I’m always happy to have a chat and collaborate at hello@sullivandecarli.com. Consider subscribing to enjoy unlimited access to my articles and all of Medium through my referral link.

--

--

Sullivan De Carli
Swift Productions

Consultant in iOS Dev at Deloitte. I write about Design & App development. Let’s have a chat at hello@sullivandecarli.com