|
I'm trying to understand a little how the View protocol from SwiftUI works. So we have this:
I have two questions about this: Is Body placeholder replaced with the actual View type (for example Text, Button, Image, VStack, etc?) What does "Self.Body" means? Give me some examples please. |
|
Maybe this will help - Self vs self So if you pass 'Text' to the 'View', 'Self.Body' will be essentially the same as 'Text.Body', and you say you can pass anything that conforms to the 'View' protocol. |
|
I think Self always refer to the conforming Type of the protocol, for example:
Here, But I dont understand why they refer to
|
|
If you have a type somewhere else in your code called By using
Yes, and those types can get very complicated very fast. This
has a
* example from Thinking in SwiftUI v2.0 by Chris Eidhof and Florian Kugler |
|
Thank you very much, now is clear for me, I didn't know Swift would confuse if I have something else called Body. Now it makes sense. SwiftUI is making sure that Body is coming from "MyCustomView.Body" and not some independent Body type. |
SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's all new Paywall Editor allow you to remotely configure your paywall view without any code changes or app updates.
Sponsor Hacking with Swift and reach the world's largest Swift community!
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.
Link copied to your pasteboard.