Chapter 4 Issues

I’ve just started on this book and have run into a few issues:

  1. Chapter 4, Page 108 of the ebook, under the “Creating a form” title. The current (as of May 10 2022) version of Xcode throws an error because the Section method is missing a Content part.

“Generic parameter ‘Content’ could not be inferred”
“Missing argument for parameter ‘content’ in call”

I realise this book was released in May 2021 and hasn’t had an update since then.

Is it getting an update? or should I move to another book?

Thanks

Played around with it a bit.

I read ahead and found the code needed for the “content” section then used the documentation and autocomplete to create the following code:

Section {
       ForEach(exercises1, id: \.self) { exercise in Text(exercise)}
        } header: {
          Text(today.formatted(as: "MMM d")).font(.headline)
        }
                
Section {
     ForEach(exercises2, id: \.self) { exercise in Text(exercise)}
        } header: {
            Text(yesterday.formatted(as: "MMM d")).font(.headline)
        }

Which displays well in the Canvas and I think does what it is supposed to do.

1 Like

thanks Brett! we’ll be updating the book after WWDC and I’ve made a note to fix this.

2 Likes

Oh that’s great to hear @Audrey !

I’m loving the book and after being away from iOS development for the last 4 years its making learning the new stuff easy and fun. Thanks.

1 Like

thanks!! also check out SwiftUI by Tutorials for more apps and different approaches (different authors)

1 Like

Yep I have that book as well. Figured I go back to the start to relearn and refresh everything.

1 Like

Following on from this, Page 139 of the ebook where it says “Replace the Form closure with the following:”, I’ve used this and it seems to work.

Form{
                    ForEach(history.exerciseDays) {day in
                        Section {
                            ForEach(day.exercises, id: \.self){
                                exercise in
                                Text(exercise)
                            }
                        } header: {
                            Text(day.date.formatted(as: "MMM d")).font(.headline)
                        }
                    }
                }
1 Like

Page 133 of the ebook. Under “Refactoring ContentView and ExerciseView”

It says to replace the ForEach loop with

ForEach(0 ..< Exercise.exercises.count) { index in

But this gave a warning and a bit of reading and googling suggested to change it to this

ForEach(0 ..< Exercise.exercises.count, id:\.self)

I’m not 100% sure why, but it removed the warning and it works.

1 Like