I have a struct "Person
" which I want to reassign each individual object's amount
from the structArray
which I declared. When I do a for each loop to reassign the amount
, an error says
Left side of mutating operator isn't mutable: 'person' is a 'let' constant
struct Person {
let name : String
var amount : Double
}
var structArray:[Person] = []
func calculateBill(pax: [Person]) -> [Person] {
for person in pax {
person.amount += taxByPerson //error
}
return pax
}
What is causing the issue and how can I fix this to be able to reassign the value?
EDIT: Thanks guys for pointing out where my error was, although the downvoting is pretty depressing to watch lol.
func calculateBill(pax: [Person]) -> [Person] {
var finalBill:[Person] = pax
for i in 0..<finalBill.count {
finalBill[i].amount += taxByPerson
}
return finalBill
}