Delete Multiple Rows from List in SwiftUI

DevTechie
DevTechie
Published in
3 min readNov 26, 2022

--

Delete Multiple Rows from List in SwiftUI

List is one of the most used and convenient view in SwiftUI. Lists combined with ForEach adds a few more cool features to the List views.

Today we will explore multi-row delete functionality for List.

We will start with a list of DevTechie courses in a State array property.

struct DevTechieDeleteFromListExample: View {

@State private var courses = ["Mastering WidgetKit iOS 16", "Practical iOS 16", "New in SwiftUI: Charts", "Complete Machine Learning"]

Next we will add variable for EditMode which is a mode that indicates whether the user can edit a view’s content.

struct DevTechieDeleteFromListExample: View {

@State private var courses = ["Mastering WidgetKit iOS 16", "Practical iOS 16", "New in SwiftUI: Charts", "Complete Machine Learning"]
@State private var editingMode = EditMode.inactive

We will add one more State property, this one will hold selections from the List view.

struct DevTechieDeleteFromListExample: View {

@State private var courses = ["Mastering WidgetKit iOS 16", "Practical iOS 16", "New in SwiftUI: Charts", "Complete Machine Learning"]
@State private var editingMode = EditMode.inactive
@State private var selectedItems = Set<String>()

--

--