【发布时间】:2016-11-26 15:54:59
【问题描述】:
func answersAndResults (answerIndex: Int, link: Dictionary <Int, Int>) {
if inputIndex == answerIndex {
for (linkedResult, weight) in link {
linkedResult += weight // Left side of mutating operator isn't immutable: "linkedResul" is a let costant
}
}
}
如何使用 for in 循环动态更改字典的值
【问题讨论】:
-
无关,但您需要学习使用正确的命名约定。只有类名应该以大写字母开头。变量、方法和参数名称都应以小写字母开头。你的函数应该是
func answersAndResults (answerIndex: Int, link: Dictionary <Int, Int>)。遵循标准使您的代码更容易被其他人阅读。
标签: swift dictionary for-loop