I have a very simple problem with Swift. I created this function:
var dictAges : [String: Int] = ["John":40, "Michael":20, "Bob": -16]
func correctAges(dict:[String:Int]) {
for (name, age) in dict {
guard age >= 0 else {
dict[name] = 0
continue
}
}
}
correctAges(dict:dictAges)
But I don't understand the error:
"cannot assign through subscript: 'dict' is a 'let' constant, dict[name] = 0"
How can I solve it?