I've got 3 errors on line scrum.update(from: data) :
- Argument passed to call that takes no arguments
- Cannot use mutating member on immutable value: 'self' is immutable
- 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]))
}
}
}