首页 > 解决方案 > 如何更新字典中特定索引处的键和值?

问题描述

获取源索引的详细信息并通过存储它来删除这些值

但是如何在目的地或目的地索引处添加存储的数据???

正在使用字典键和值在自定义单元格/行中显示数据

这里我试图将表格视图中的单元格从源移动到目标。

获取源索引和删除的详细信息工作正常,但如何在目标或目标索引添加相同的数据???

这是我的代码:

let indexSource = dic1.index(forKey: (Array(dic1.keys)[sourceIndexPath.row]))

let rearrangedDataDic = dic1[indexSource!]

dic1.remove(at: indexSource!)

let indexDest = dic1.index(forKey: (Array(dic1.keys)[destinationIndexPath.row]))

dic1.updateValue(rearrangedDataDic.value, forKey: rearrangedDataDic.key)

标签: swiftdictionary

解决方案


推荐阅读