2

I am following the ios app development tutorial for the Scrumdinger app and I have followed the tutorial and it has worked until I finished the Passing Data with Binding Section. I keep gettin an error on my line 58 "DetailEditView(data: $data)". This is exactly what the tutorial says to put so I do not know why I am gettin the error.

This is my full code for the Detail View File: "

// // DetailView.swift // Scrumdinger // // Created by ZOE HEIM on 4/25/22. // import Foundation 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) } } } } } } } struct DetailView_Previews: PreviewProvider { static var previews: some View { NavigationView { DetailView(scrum: .constant(DailyScrum.sampleData[0])) } } } 

" Here is the link to the tutorial I am following as well:

https://developer.apple.com/tutorials/app-dev-training/passing-data-with-bindings

1
  • 3
    Where is your code for DetailEditView? Commented Apr 27, 2022 at 15:46

2 Answers 2

8

Seems you are following the tutorial from the start, which is logical. However, the project files of this lesson includes a modification of DailyScrum.swift, which defines update() as follows.

mutating func update(from data: Data) { title = data.title attendees = data.attendees lengthInMinutes = Int(data.lengthInMinutes) theme = data.theme } 
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you! Very confusing of Apple's tutorial to not mention that they make changes behind the scenes inbetween.
-1

In section 2 step 8 of the tutorial data property of DetailEditView is declared as

@State private var data = DailyScrum.Data()

which is initialized at declaration time, so DetailEditView has no initializer at this point.

Now see Section 3 step 1 where data property is modified as

@Binding var data: DailyScrum.Data

and now DetailEditView has inferred initializer which we can use as

DetailEditView(data: some binding var)

6 Comments

The error is on DetailEditView(data: $data) which is not the same.
Sorry my bad, can you share DetailEditView code?
please check the answer now, hope it will help.
I am not OP and since we don’t know what DetailEditView looks like I guess this is mostly a guess.
I saw detailEditView in the tutorial you shared the link.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.