我有这样一本字典......
[
"113": SellerApp.Product(name: "aaaa", id: "113", images: [SellerApp.ProductImage(myId: "996", url: http://myApp.com/public/uploads/products/123_113_1_image_123456789, isDefault: true)], theRate: "234", quantity: "17", sku: "Hdjsu", prdCateg: "tr123", prodDescr: "Gdhd", mrp: "520"),
"101": SellerApp.Product(name: "dfg", id: "101", images: [SellerApp.ProductImage(myId: "982", url: http://myApp.com/public/uploads/products/563_101_1_image_1011121314, isDefault: true)], theRate: "123", quantity: "7", sku: "345", prdCateg: "tr123", prodDescr: "Test", mrp: "234")
]
现在这些值中的每一个都与一个 tableviewcell 相关联。因此,当我删除特定单元格时,与其关联的所有值都应该被删除。因此,如果我删除第一个单元格,那么在上面的代码片段中,所有值都来自 "113": SellerApp.Product(name: "aa...
to mrp: "520")
应该被删除。
我试过这样的...
for (index, dict) in self.appDelegate.myDictionary1.enumerated() {
if dict.key == (self.appDelegate.commonArrForselectedItems[indexPath.section].id) {
self.appDelegate.myDictionary1.removeValue(forKey: self.appDelegate.commonArrForselectedItems[indexPath.section].id)
}
}
但这似乎删除了 id 本身,所有剩余的值都存在。我如何从字典中删除与此 ID 关联的所有值..?
最佳答案
@bvt,尝试像下面的代码一样删除值
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
yourArrayName.remove(at: indexPath.row)
}
希望能解决您的问题。
关于ios - 从字典中删除整个元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47468663/