Extract SwiftUI views from ViewBuilder content.
Follow the instructions at Adding Package Dependencies to Your App to find out how to install the Swift package. Use the link of this GitHub repo as the URL (https://github.com/GeorgeElsham/ViewExtractor).
Create a vertical stack of views, separated by dividers.
structDividedVStack<Content:View>:View{@ViewBuilderletcontent:Contentvarbody:someView{Extract(content){ views inVStack{letfirst= views.first?.id
ForEach(views){ view inif view.id != first {Divider()}
view
}}}}}DividedVStack{Text("View 1")Text("View 2")Text("View 3")}Create a vertical stack of views, only keeping views at indexes with a multiple of 2.
structIntervalVStack<Content:View>:View{@ViewBuilderletcontent:Contentvarbody:someView{Extract(content){ views inVStack{ForEach(Array(zip(views.indices, views)), id: \.1.id){ index, view inif index.isMultiple(of:2){
view
}}}}}}IntervalVStack{ForEach(0..<10){ index inText("Index: \(index)")}}Create a stack of views, returning multiple views as a result, allowing it to be wrapped by another view. When modifiers are applied, they apply to each view returned. Note the use of ExtractMulti rather than just Extract.
structDivided<Content:View>:View{@ViewBuilderletcontent:Contentvarbody:someView{ExtractMulti(content){ views inletfirst= views.first?.id
ForEach(views){ view inif view.id != first {Divider()}
view
}}}}HStack{Divided{Text("View 1")Text("View 2")Text("View 3")}.border(Color.red)}

