'Delete a dictionary key and value through .onDelete(perform: delete)
The list below is populated with a Dictionary
@State private var currencyList: [String:String] = [:]
The delete function is as follows, however IndexSet is not applicable for a dictionary.
func delete(at offsets: IndexSet){
print(" currency list before \(currencyList)")
currencyList.remove(atOffsets: offsets)
print(" currency list after \(currencyList)")
}
List{
ForEach(currencyList.sorted(by: >), id: \.key){ key, value in
HStack{
Image(systemName: "centsign.circle")
Text(value)
Text(key)
}
}.onDelete(perform: delete)
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
