This is not a question, but rather the solution and an explanation of a missing step in the iOS App Dev Tutorial. I hope this helps somebody else encountering the same issue and ultimately leads to a change to the tutorial.
There is a step missing from the iOS App Dev Tutorial under the Passing Data with Bindings part in Section 3 before Step 6. Namely, the update function has not been defined on the DailyScrum struct. This results in the following errors in DetailView.swift when calling 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<DailyScrum>'
The files for the complete project at the end of the Passing Data with Bindings part provides the solution: you must add an update function to the DailyScrum model.
Add the following inside the extension DailyScrum code block:
mutating func update(from data: Data) {
title = data.title
attendees = data.attendees
lengthInMinutes = Int(data.lengthInMinutes)
theme = data.theme
}
When complete, your DailyScrum.swift file should appear as follows at this stage in the tutorial.
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)
]
}