Black Friday deal: 30% off our book "Integrating SwiftUI into UIKit apps"! Learn more ...Black Friday deal:30% off "Integrating SwiftUI into UIKit apps" >>
Quick Tip Icon
Quick Tip

Automatically generated List edit operations

Starting from iOS 16 and macOS 13 SwiftUI List view can automatically generate move and delete operations without the need of onMove and onDelete closures.

To create a simple editable list, we can pass a binding to a collection to the List view and provide a set of edit operations we want to allow.

struct ContentView: View {
    @State var items = ["A", "B", "C"]
    
    var body: some View {
        NavigationView {
            List(
                $items, id: \.self,
                edits: [.delete, .move]
            ) { $item in
                Text(item)
            }
        }
    }
}

You can see the available options in the documentation for EditOperations.

If we don't want to allow deletion of certain rows, we can use deleteDisabled() modifier on a per row basis.

Integrating SwiftUI into UIKit Apps by Natalia Panferova book coverIntegrating SwiftUI into UIKit Apps by Natalia Panferova book cover
Black Friday offer
Our book "Integrating SwiftUI into UIKit apps" is now 30% off!

Discover various ways to adopt SwiftUI in existing UIKit projects and take full advantage of the new iOS 16 frameworks and APIs such as Swift Charts.

The offer is active until the 1st of December.