SwiftUI, List, .onDelete(perform: ) and Firestore

I created a list with the ability to delete lines by the method: .onDelete (perform:).

List {
   ForEach(itemList.dataLocation) { item in
      NavigationLink(destination: ListDetails(name: item.nameDB)) {
           ListItem(name: item.nameDB)
      }
   }
   .onDelete(perform: delete)
   .onMove(perform: move)
}


func delete(at offsets: IndexSet) {
        itemList.dataLocation.remove(atOffsets: offsets)
        session.deleteData(id: //id row) //this problem
}

How to pass the value of a deleted string to a function? It is advisable to still get data from this row. Thanks in advance!

Upvotes: 2

Views: 1366

Answers (1)

joekim
joekim

Reputation: 199

In the delete function offsets is an IndexSet of the items that got deleted. Normally it would be a set of one element.

func delete(at offsets: IndexSet) {
  for index in offsets {
    session.deleteData(id: itemList.dataLocation[index].id) // problem solved
  }
  itemList.dataLocation.remove(atOffsets: offsets)
}

Upvotes: 6

Related Questions