Post

Replies

Boosts

Views

Activity

Cannot use mutating member on immutable value: 'self' is immutable
why is error in swiftUI body? struct ContentView: View {     @Converter("100", from: "USD", to: "CNY", rate: 6.78) var usd_cny     var body: some View {         VStack(alignment: .leading, spacing: 10) {             Button(action: {                 update("200")             }) {                 Text(self.$usd_cny)             }         }     }     mutating func update(_ price: String) {         self.usd_cny = price     } } @propertyWrapper struct Converter {     var from: String     var to: String     var rate: Double     var value: Double     var wrappedValue: String {         get { "\(from)\(value)"}         set { value = Double(newValue) ?? -1}     }     var projectedValue: String {         return "\(to)\(value * rate)"     }     init(_ value: String, from: String, to: String, rate: Double) {         self.rate = rate         self.value = 0         self.from = from         self.to = to         self.wrappedValue = value     }     mutating func update(_ value: String) {         self.wrappedValue = value     } } struct ContentView_Previews: PreviewProvider {     static var previews: some View {         ContentView()     } }
5
0
13k
Jul ’20