Member-only story

Swipe Actions in SwiftUI

Gabriel Theodoropoulos
CodeX
Published in
7 min readJul 9, 2021
Image by Firmbee from Pixabay

Swipe actions is not a new concept in iOS or macOS programming. We have been using such actions for years in Apple’s applications, with a quite typical example being the Mail app. Programmatically we know them from the table view in UIKit, where we implement them in order to allow users to perform specific operations on individual cells. In SwiftUI swipe actions had not been available until WWDC 2021; it was there where it was eventually announced that the third release of SwiftUI was going to support such actions natively. In this post we are about to explore this topic, and have a hands-on experience on how to integrate swipe actions in SwiftUI.

A demo scenario

Let’s suppose that we have the next list of old movies:

Credits: Top rated movies from IMDB.

Our goal here is to add swipe actions to both the leading and trailing edges of each row, so we can do the following:

  • Indicate whether the user has watched a movie or not.
  • Indicate whether the user watched that movie alone or with friends, i.e. in a cinema.
  • Remove a movie from the list in case the user does not like it.

--

--

CodeX
CodeX

Published in CodeX

Everything connected with Tech & Code. Follow to join our 1M+ monthly readers

Gabriel Theodoropoulos
Gabriel Theodoropoulos

Written by Gabriel Theodoropoulos

An iOS & macOS app maker writing code in Swift. Author of countless programming tutorials. Content creator. https://serialcoder.dev

No responses yet

Write a response