How do I add an "insert" feature like UITableViewCell.EditingStyle in SwiftUI?

In UIKit, it's quite common for table views to have one (or sometimes more) rows whose editing style is "insert", which show up a button with a plus symbol on a green background to the left of the cell content, and tapping this button adds whatever is in the cell content (usually a text field) to the list.

What's the procedure for creating a list row like this in Swift UI when in edit mode?

I'm not sure if there's a built-in way of doing it, but you can add swipeActions to a row, then perform an action based on the button tapped.

var body: some View {
    List {
        ForEach(etc.) { element in
            RowView(rowData: element)
                .swipeActions(edge: .leading, allowsFullSwipe: false) {
	                  MySwipeButtonsView(rowData: element)
                }
        }
    }
}

struct MySwipeButtonsView: View {
	var rowData: RowDetails  // The type for the row data

	var body: some View {
		Button {
			insertRow()  // Insert a row above/below in your array, and SwiftUI should redraw the list if you've set up an observable model etc.
		} label: {
			Label("", systemImage: "plus")
				.symbolRenderingMode(.palette)
				.labelStyle(.iconOnly)
				.tint(Color.green)
				.foregroundStyle(Color.white)
		}
	}
}

You should checkout EditMode environment value.

It isn't a 1-1 functionality mapping, but certain built-in SwiftUI views will automatically alter their appearance and behavior in edit mode. For example, a List with a ForEach that’s configured with the onDelete(perform:) or onMove(perform:) modifier will provide controls to delete or move list items while in edit mode.

How do I add an "insert" feature like UITableViewCell.EditingStyle in SwiftUI?
 
 
Q