SwiftUI: How to delete or move List rows?

--

Delete a row:

In SwiftUI user can easily delete the row by adding .onDelete(perform:) handler to the row. The action to perform by SwiftUI when rows in the List are deleted. SwiftUI passes a set of indices for deleting the rows..

Move a row:

To move a row from one index to another use .onMove(perform:) . This is a closure that is invoked by SwiftUI when rows in the List are moved. This closure takes two arguments that represent the old offset of row and new offset of row where it need to be moved.

Note: To disable moving of rows in editing mode pass nil to closure. .onMove(perform: nil)

So, complete implementation for deleting or moving a row will look like below:

List to delete row with swipe(without edit mode).
List with edit mode which enables both deleting and moving of row.

Sample Code

--

--

Priyanka Saroha

iOS developer with almost 9 years of rich experience which includes a good knowledge of ObjectiveC, Swift, SwiftUI and AR.