Stuck in the SwiftUI Tutorial by Apple in Chapter 5 (Updating App data)

import SwiftUI

struct ScrumsView: View {
    @Binding var scrums: [DailyScrum]
    @State private var isPresentingNewScrumView = false
    @State private var newScrumData = DailyScrum.Data()
    
    var body: some View {
        List {
            ForEach($scrums) { $scrum in
                NavigationLink(destination: DetailView(scrum: $scrum)) {
                    CardView(scrum: scrum)
                }
                .listRowBackground(scrum.theme.mainColor)
            }
        }
        .navigationTitle("Daily Scrums")
        .toolbar {
            Button(action: {
                isPresentingNewScrumView = true
            }) {
                Image(systemName: "plus")
            }
            .accessibilityLabel("New Scrum")
        }
        .sheet(isPresented: $isPresentingNewScrumView) {
            NavigationView {
                DetailEditView(data: $newScrumData)
                    .toolbar {
                        ToolbarItem(placement: .cancellationAction) {
                            Button("Dismiss") {
                                isPresentingNewScrumView = false
                                newScrumData = DailyScrum.Data()
                            }
                        }
                        ToolbarItem(placement: .confirmationAction) {
                            Button("Add") {
                                
                                
                                
                                
                                let newScrum = DailyScrum(data: newScrumData)
                                scrums.append(newScrum)
                                isPresentingNewScrumView = false
                                newScrumData = DailyScrum.Data()
                                
                             
                                
                            }
                        }
                    }
            }
        }
    }
}

struct ScrumsView_Previews: PreviewProvider {
    static var previews: some View {
        NavigationView {
            ScrumsView(scrums: .constant(DailyScrum.sampleData))
        }
    }
}

This is the ScrumsView and I get 2 Erros in Line let newScrum = DailyScrum(data: newScrumData)

It says: "Extra argument 'data' in call" & "Missing arguments for parameters 'title', 'attendees', 'lengthInMinutes', 'theme' in call"

I followed each step of the tutorial and I even downloaded the completed file of the next chapter but that didn't help me either. I looked in forums and I found that there was a func missing in the tutorial in the extension DailyScrum, but even after I added this func it still didn't work. Here is the DailyScrum File for context:

import Foundation

struct DailyScrum: Identifiable {
    let id: UUID
    var title: String
    var attendees: [Attendee]
    var lengthInMinutes: Int
    var theme: Theme
    
    init(id: UUID = UUID(), title: String, attendees: [String], lengthInMinutes: Int, theme: Theme) {
        self.id = id
        self.title = title
        self.attendees = attendees.map { Attendee(name: $0) }
        self.lengthInMinutes = lengthInMinutes
        self.theme = theme
    }
}

extension DailyScrum {
  struct Attendee: Identifiable {
    let id: UUID
    var name: String
     
    init (id: UUID = UUID(), name: String) {
      self.id = id
      self.name = name
    }
  }
   
  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
  }
}


extension DailyScrum {
    static let sampleData: [DailyScrum] =
    [
        DailyScrum(title: "Design", attendees: ["Cathy", "Daisy", "Simon", "Jonathan"], lengthInMinutes: 10, theme: .yellow),
        DailyScrum(title: "App Dev", attendees: ["Katie", "Gray", "Euna", "Luis", "Darla"], lengthInMinutes: 5, theme: .orange),
        DailyScrum(title: "Web Dev", attendees: ["Chella", "Chris", "Christina", "Eden", "Karla", "Lindsey", "Aga", "Chad", "Jenn", "Sarah"], lengthInMinutes: 5, theme: .poppy)
    ]
}

Does someone have a solution for this?

Answered by ConfusedCaribou in 722927022

This error you are seeing is because the you are missing arguments from the DailyScrum initialiser. When you call DailyScrum(data: …), you are trying to call the initialiser for daily scrum that would look like:

init(data: Data) { 
…
}

But this doesn’t exist in your code (you might’ve missed it from the tutorial?). The only initialiser for the DailyScrum struct in your code is

init(id: UUID = UUID(), title: String, attendees: [String], lengthInMinutes: Int, theme: Theme) { … }

So you would need to use this list of arguments to initialise that struct instead. I have not seen the tutorial but it looks like you might’ve forgotten to copy some bits or maybe missed a step - hope this helps!

Accepted Answer

This error you are seeing is because the you are missing arguments from the DailyScrum initialiser. When you call DailyScrum(data: …), you are trying to call the initialiser for daily scrum that would look like:

init(data: Data) { 
…
}

But this doesn’t exist in your code (you might’ve missed it from the tutorial?). The only initialiser for the DailyScrum struct in your code is

init(id: UUID = UUID(), title: String, attendees: [String], lengthInMinutes: Int, theme: Theme) { … }

So you would need to use this list of arguments to initialise that struct instead. I have not seen the tutorial but it looks like you might’ve forgotten to copy some bits or maybe missed a step - hope this helps!

There are some errors in the course of the tutorial. But if you get the complete finished project, you will get the correct solution.

Thank you @ConfusedCaribou , that was the problem. Unfortunately, they didn't include this in the tutorial, they just skipped this step ...

I honestly don't get why they make it sound like you will build a project following their tuto while actually YOU HAVE TO download some starter project for some sections to make sure you get some pieces of code that they don't show or explain. It is so confusing. Its a shame, when they actually show/explain, it is quite clear and concise.

Stuck in the SwiftUI Tutorial by Apple in Chapter 5 (Updating App data)
 
 
Q