Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SwiftUI List onDelete IndexSet to int

Tags:

swift

swiftui

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.


1 Answers

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.

like image 140
Dawood Siddique Avatar answered Oct 26 '25 23:10

Dawood Siddique