Michaela slings a complicated view then gets stumped by the error message:
I get the error: "Generic parameter 'Content' could not be inferred" error
on my VStack under my NavigationView.
I assume it has something to do with the sheets, but I'm not sure.
This is a great lesson for you!
You have a complicated View
and one misplaced bracket can cause complex errors.
In short, an HStack
, a VStack
, a NavigationView
, a ForEach
view builder must, in the end, deliver a fully functional view to the compiler to render to the screen.
If even one bracket is out of place, the compiler cannot infer the content of the view. This is a job you can unravel.
Make a copy of your PlusWorkoutView
. Then remove all the decorations and empty lines. Bold, padding, background colors. Get rid of all of that. Delete all the empty lines.
Next simplify yourview with just Text("VStack #1")
and Text("HStack #3")
type of comments. Compact your PlusWorkoutView
down to its simplest form. Once you get it to compile and you can see a rough view in a simulator, slowly add back Pickers
, and decorators. Pay careful attention to where they belong in your hierarchy.
Finally, think about your architecture. Why is this view so complex? Think about what parts of this complex view might be broken out into reuseable Lego Brick type views. Small, standalong parts that you can reuse elsewhere in your application.
For example, perhaps part of this complex view can be pulled out and made into a HeaderView()
and another part turned into a FooterView()
. This may not apply to your code, but it's something to consider.