Left side of mutating operator isn't mutable: 'visiter' is a 'let' constant? WHY?

at the point where I tried to subtract the costs from the money of the guest, the error ”Left side of mutating operator isn’t mutable: ‘visiter’ is a ‘let’ constant” was throw when I tried to use the operator -= But why? I declared it as variable! What can I do? The error was thrown at the entry function and the bar function:

struct ClubGuest: Guest {     var name: String     var money: Double     var onDrugs: Bool } var mikel = ClubGuest(name: "Mikel", money: 50.5, onDrugs: false) var angelina = ClubGuest(name: "Angelina", money: 400, onDrugs: true) var steve = ClubGuest(name: "Steve", money: 100.80, onDrugs: true) var july = ClubGuest(name: "July", money: 1050, onDrugs: false)  struct Club: Party {     var name: String     var location: String     var entryPrice: Double     var guests: [Guest]     var maximumguests: Int     var revenue = 0.0     mutating func entry(visiter: Guest) {         if visiter.money > entryPrice && guests.count < maximumguests {             guests.append(visiter)             visiter.money -= entryPrice             revenue += entryPrice         } else {             stop()         }         GuestCheckUP(guest: visiter)     }          mutating func Bar(guest: Guest, drink: Drink) {         print("\(guest) want to buy a drink")         if guest.money >= drink.price {             guest.money -= drink.price         revenue += drink.price         print("\(guest.name) bought a \(drink.name) for \(drink.price)$, now he/she has \(guest.money)$ in his/her pocket")         } else {             print("\(guest.name) has too less money for a drink!")         }     }               mutating func GuestCheckUP(guest: Guest) {         if guest.onDrugs {             throwOut(visiter: guest)                      }     }               mutating func throwOut(visiter: Guest) {         print("\(visiter.name) was throwed out by the security!")     }          func stop() {         print("Stop! No entry!")     }     func Earnings() {         print("The earnings of tonight are \(revenue)$")     } } 
Add Comment
0 Answer(s)

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.