The some View is a general Swift feature called opaque types. And of course Paul Hudson has a great explanation of it.
some View
The important thing to keep in mind there is that you have to always return the same actual type of View from body. So if you have an if statement inside body, you cannot return, say, a VStack from one branch and a Text from the other. You need to wrap either the if statement in a Group or wrap all your returned views in an AnyView.
View
body
if
VStack
Text
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
The
some View
is a general Swift feature called opaque types. And of course Paul Hudson has a great explanation of it.The important thing to keep in mind there is that you have to always return the same actual type of
View
frombody
. So if you have anif
statement insidebody
, you cannot return, say, aVStack
from one branch and aText
from the other. You need to wrap either the if statement in a Group or wrap all your returned views in an AnyView.