Skip to content

Instantly share code, notes, and snippets.

@shaps80
Created December 22, 2023 10:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shaps80/f1783efea58c77dce2f0abaf548ec77f to your computer and use it in GitHub Desktop.
Save shaps80/f1783efea58c77dce2f0abaf548ec77f to your computer and use it in GitHub Desktop.
Enables the creation of custom container views in SwiftUI
import SwiftUI
public extension View {
func variadic<R: View>(@ViewBuilder _ transform: @escaping (_VariadicView.Children) -> R) -> some View {
_VariadicView.Tree(Helper(transform: transform)) { self }
}
}
private struct Helper<R: View>: _VariadicView.MultiViewRoot {
var transform: (_VariadicView.Children) -> R
func body(children: _VariadicView.Children) -> some View {
transform(children)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment