Swipe Actions on Lists with SwiftUI

By the end of this article, you will be able to add swipe actions to your lists using SwiftUI and new modifiers introduced at WWDC 2021.

Swipe Actions on Lists with SwiftUI

One of the great new features added to SwiftUI on WWDC 2021 was the addition of a simple way to add swipe actions to your lists. With a simple modifier, you can add custom actions to your list items.

Let’s start by creating a simple list of names.

struct ContentView: View {
    
	var contacts: [String] = ["Tiago Pereira", "Moritz Recke", "Giovanni Monaco"]
    
	var body: some View {

		// Creating a simple list of names
		List(contacts, id: \.self) { name in
			Text(name)
		}

	}
}
A simple list to be used in the examples that follow.

Now, let's see how to add swipe actions. Become a free member or log in to proceed.