Urgent!
I can't use update with scrum. How can I fix this?
If you're such in a hurry, you should give information to help helping you.
And post the code itself, not only a screenshot, so that we can understand the context, aww ell as an exact reference of the tutorial page.
https://developer.apple.com/tutorials/app-dev-training/passing-data-with-bindings
You have probably missed something in the code and did not follow the tutorial instructions.
Is it the tutorial below ? What is your exact code ?
You have probably not do what is instructed, to replace
let scrum: DailyScrum
by
@Binding var scrum: DailyScrum
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("Attendees")) {
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)
}
}
}
}
}
}
}
In the DailyScrum extension, you need the code:
mutating func update(from data: Data) {
title = data.title
attendees = data.attendees
lengthInMinutes = Int(data.lengthInMinutes)
theme = data.theme
}
This appears in the "Passing Data with Bindings" section downloadable completed code, but I think it may be missing from the step-by-step instructions (or I missed seeing it).
Had the same issue and DDP's solution worked for me.
Leaving this comment to bump this thread and this solution. Hopefully, Apple will see this and update the Scrumdinger guide to include this little bit, because, for anyone that's just learning, this would be extremely hard to figure out on their own.