What does the `some` keyword mean in Swift (and SwiftUI)? Explain for beginners
Hello everyone! I'm learning Swift and SwiftUI, and I constantly see the `some` keyword in code. For example:
```swift
struct ContentView: View {
var body: some View {
Text("Hello, World!")
}
}
```
I understand that `some` comes before the `View` type, but I can't understand why it's needed. Why can't we just write `var body: View`? After all, `Text` is also a `View`. I tried removing `some` — Xcode complains and says something about protocols.
I've read that this is related to Opaque Types and the fact that Swift can't work with protocols that have Self or associated types. But this sounds very complicated.
Please explain in simple terms: what does `some` do, why is it needed specifically in SwiftUI, and how does it work under the hood? Give examples of when `some` is
No answers yet.
Log in to leave an answer
Blogs