Module 2 Lesson 16 - Opaque Return

In my “DetailView” I keep getting an opaque return type error no matter what I did that might have fixed it, I checked the solution and the same problem occurs there too. Does anyone know how to to remedy this? (I’m aware that the types aren’t related to the original challenge and that the file isn’t actually called DetailView)

Hi @ethinmck000

Welcome to the Community.

Just so that I am clear, you download the solution and when you ran it, the same thing occurred?

You might be best advised to create a new project and name everything in line with the subject matter rather than using code from another project to make it work.

The challenge is about famous quotes from particular authors so the detailView is dealing with an author and a series of quotes from that author rather than a pizza and a series of toppings.

What should the body display if type is nil? You need to cover every execution path or you’ll get an error.

Also, since you are hiding the view code behind an if, you need to explicitly return something. So, return VStack(...) { blah blah blah } for the true path and return Text("we got no pizza") or whatever for the other path.

For the purpose of the exercise I made a copy of my version and placed your code inside the swift file that is effectively the DetailView (mine is QuoteDetailView) and then used your code in the same manner you have including the fact that you have set var type: Pizza? as Optional.
(I had: var type: Quote?)

It complied, ran fine and there were no errors.

Perhaps all you need to do is Clean your Project Build folder (Shift + Command + K) and you may be OK.

I copied the challenge and fixed my own code to return the VStack, tried adding a else path, and even updated my computer to see if it was a bug, but my project still wont load.


(now with returns)

I also tried this

You don not need a return in front of your VStack.