我无法尝试更新我的多维数组。首先,我过滤了一个名为 title 的特定字符串,它用作我的标识符。然后我想替换这个过滤后的数组的描述值。
我已经尝试用类似 rowContent[1] = descriptionTranferred
的方式解决这个问题(索引 1 处的值是描述,应替换为 descriptionTranferred 中的值)。我也尝试了 rowContent.description = descriptionTranferred
,但也没有成功。
有什么方法可以更新数组中的描述值吗?
这是我的代码:
SWIFT 3
var rowContent = Array<(title: String, description: String)>()
func transferData(descriptionTranferred: String, identifier: String) {
if rowContent.contains(where: {$0.title == identifier}) {
rowContent[1] = descriptionTranferred
} else {
print ("nothing")
}
}
最佳答案
它不是多维数组,而是具有命名参数的元组数组。尝试:
rowContent[1].description = descriptionTranferred
但我猜您正在尝试更改元组中与标识符匹配的索引的描述,因此请替换您的 if
条件:
if let index = rowContent.index(where: {$0.title == identifier}) {
rowContent[index].description = descriptionTranferred
}else {
print ("nothing")
}
关于ios - 更新具有特定索引的元组数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40007386/