Post

Replies

Boosts

Views

Activity

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?
4
1
1k
Aug ’22