Skip to content

Instantly share code, notes, and snippets.

@sturdysturge
Created October 17, 2022 23:02
Show Gist options
  • Select an option

  • Save sturdysturge/fe38d736d099177838698268593ef68e to your computer and use it in GitHub Desktop.

Select an option

Save sturdysturge/fe38d736d099177838698268593ef68e to your computer and use it in GitHub Desktop.
import SwiftUI
protocol MyView {
associatedtype Body : View
// Apple adds @ViewBuilder here in the View protocol
var body: Self.Body { get }
}
struct ConformingView: MyView {
// @ViewBuilder needed because multiple values are returned
@ViewBuilder
var body: some View {
Text("One")
Text("Two")
Text("Three")
}
// @ViewBuilder not needed because type is inferred to be
// Group<TupleView<(Text, Text, Text)>>
var oneConcreteType: some View {
Group {
Text("One")
Text("Two")
Text("Three")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment