SwiftUI List EditActions

Published by malhal on

It’s hard to find this feature in the documentation so thought I’d share an example here.

import SwiftUI

struct EditableListTest: View {
    @State var items: [ListItem] = [ListItem(text: "Test 1"), ListItem(text: "Test 2")]
    
    var body: some View {
        NavigationView {
            List($items, editActions: [EditActions.all]) { $item in
                Text(item.text)
            }
            .toolbar {
                EditButton()
            }
        }
    }
}

struct ListItem: Identifiable {
    let id = UUID()
    var text = ""
}