BLACK FRIDAY SALE: Save big on all my Swift books and bundles! >>

Generic Parameter ERROR

Forums > SwiftUI

Hello, I'm sure this has been an error that has been encountered many times, but I can't seem to find anything on the web that I understand, so hopefully someone here could help me.

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.

Here is my code:


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.


@michaelacaggi you can put your code directly into your forum post by placing backticks ``` on the line before your code block and the line after. You can manually type the backticks or you can highlight your code and hit the Code button on the toolbar. It looks like this: </>.

This makes it easier for people to help you since they don't have to go to an external site just to see the code you are having an issue with.


I concur with @rooster regarding code in the forum. There are too many adverts on that site. Plus keeping your code on this site helps others in the future should you decide to shut down you account on pastebin.


Hacking with Swift is sponsored by RevenueCat

SPONSORED In-app subscriptions are a pain to implement, hard to test, and full of edge cases. RevenueCat makes it straightforward and reliable so you can get back to building your app. Oh, and it's free if your app makes less than $10k/mo.

Learn more

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

Unknown user

You are not logged in

Log in or create account

Link copied to your pasteboard.