2

How do I convert the offesets: IndexSet value to just a plain int?

I can get a range using offsets.startIndex, but that still doesn't give me an int. startIndex seems to be the value I need to pass to the view model, so that I can update the underlying array.

  • Does this answer your question https://stackoverflow.com/a/61562459/12299030? – Asperi Nov 30 '20 at 08:12
  • Yep, that's done it, thank you... I don't know why they're not using the good ole IndexPath.row any more... –  Nov 30 '20 at 08:45
  • 2
    Does this answer your question? [How to get the index of a deleted row from a list in SwiftUI?](https://stackoverflow.com/questions/61562137/how-to-get-the-index-of-a-deleted-row-from-a-list-in-swiftui) – Caleryn Nov 30 '20 at 15:58

1 Answers1

2

You can loop through IndexSet to get the specific index of the array which user trigger to delete.

        .onDelete {indexSet in
            for index in indexSet{
                print(index)
            }
        }

There will be only one element index which will be index of array getting deleted.