Cannot use mutating member on immutable value: 'self' is immutable error

I've got 3 errors on line scrum.update(from: data) :

  1. Argument passed to call that takes no arguments
  2. Cannot use mutating member on immutable value: 'self' is immutable
  3. Referencing instance method 'update()' requires wrapper 'Binding'

When I change my code to $scrum.update(from: data) , I have the first and second errors

I'm still learning SwiftUI and trying to understand the docs, how can I fix these errors?

import SwiftUI

struct DetailView: View {
  @Binding var scrum: DailyScrum
   
  @State private var data = DailyScrum.Data()
  @State private var isPresentingEditView = false
   
  var body: some View {
    List {
      Section(header: Text("Meeting Info")) {
        NavigationLink(destination: MeetingView()) {
          Label("Start Meeting", systemImage: "timer")
            .font(.headline)
            .foregroundColor(.accentColor)
        }
        HStack {
          Label("Length", systemImage: "clock")
          Spacer()
          Text("\(scrum.lengthInMinutes) minutes")
        }
        .accessibilityElement(children: .combine)
        HStack {
          Label("Theme", systemImage: "paintpalette")
          Spacer()
          Text(scrum.theme.name)
            .padding(4)
            .foregroundColor(scrum.theme.accentColor)
            .background(scrum.theme.mainColor)
            .cornerRadius(4)
        }
        .accessibilityElement(children: .combine)
      }
      Section(header: Text("Attendee")) {
        ForEach(scrum.attendees) { attendee in
          Label(attendee.name, systemImage: "person")
        }
      }
    }
    .navigationTitle(scrum.title)
    .toolbar {
      Button("Edit") {
        isPresentingEditView = true
        data = scrum.data
      }
    }
    .sheet(isPresented: $isPresentingEditView) {
      NavigationView {
        DetailEditView(data: $data)
          .navigationTitle(scrum.title)
          .toolbar {
            ToolbarItem(placement: .cancellationAction) {
              Button("Cancel") {
                isPresentingEditView = false
              }
            }
            ToolbarItem(placement: .confirmationAction) {
              Button("Done") {
                isPresentingEditView = false
                scrum.update(from: data)
              }
            }
          }
      }
    }
  }
}

struct DetailView_Previews: PreviewProvider {
  static var previews: some View {
    NavigationView {
      DetailView(scrum: .constant(DailyScrum.sampleData[0]))
    }
  }
}

You do not show the code for update, so hard to tell exactly.

But the complete version of the project works (you can download at the end).

update is defined as follows:

    struct Data {
        var title: String = ""
        var attendees: [Attendee] = []
        var lengthInMinutes: Double = 5
        var theme: Theme = .seafoam
    }
    
    var data: Data {
        Data(title: title, attendees: attendees, lengthInMinutes: Double(lengthInMinutes), theme: theme)
    }
    
    mutating func update(from data: Data) {
        title = data.title
        attendees = data.attendees
        lengthInMinutes = Int(data.lengthInMinutes)
        theme = data.theme
    }
    
    init(data: Data) {
        id = UUID()
        title = data.title
        attendees = data.attendees
        lengthInMinutes = Int(data.lengthInMinutes)
        theme = data.theme
    }
}

Compare with your code. If it doesn't work, please detail the error you get. Otherwise, don't forget to close the thread on the correct answer.

Cannot use mutating member on immutable value: 'self' is immutable error
 
 
Q