UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

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: https://pastebin.com/TAkt3zMA

2      

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.

2      

@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.

3      

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.

2      

Hacking with Swift is sponsored by Essential Developer

SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until April 28th.

Click to save your free spot now

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

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

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.