Creating an editable List view
Adding an edit button to a List view is very similar to adding a delete button, as seen in the previous recipe. An edit button offers the user the option to quickly delete items by clicking a minus sign to the left of each list row.
Getting ready
Create a new SwiftUI project named ListRowEdit
.
How to do it…
The steps for adding an edit button to a List
view are similar to the steps we used when adding a delete button. The process is as follows:
- Replace the
ContentView
struct with the following content from theDeleteRowFromList
app:struct ContentView: View { @State private var countries = ["USA", "Canada", "Mexico", "England", "Spain", "Cameroon", "South Africa" , "Japan", "South Korea"] var body: some View { NavigationStack { List { ForEach(countries, id: \.self) { country in...