SwiftUI View require body and some keyword question

I have a question about some keyword and body

When you create a struct and you have to add them in the struct.

Does anyone know why we have to and what does some keyword mean?

Thanks

Hi @maomao,
You might want to read up on Opaque return, this is the opposite of Generics. The easiest and simplest way to describe some is that it expects a return to be of a particular type. In SwiftUI everything is a View and therefore the return type expects that it will be a View of some type. Not specifying a Button, Text, or another specific type.

That’s the best in short explanation, I hope that helps

cheers,

1 Like

Thank jay I got it haha. What does Generics and Opaque mean?

Hi @maomao,
No problems, here’s the proposal about Opaque Return types from Apple

Thanks I will take a look :slight_smile: I realised that Jay is from Melbourne as well haha and I bought Swift book here.

@maomao, cool have we met at Cocoaheads or otherwise?

not yet I think we will meet soon :slight_smile:

The some keyword is to say you function or property will always return the same actually type, for example if you declare a method that returns some Equatable, you won’t return Float on some calls and Int on others, without that there is no way to do an == between the result of two calls to your function because there is no way for the compiler to know if they are both of the same, since they could be any Equatable.

1 Like

This topic was automatically closed after 166 days. New replies are no longer allowed.