Swiftpack.co -  GeorgeElsham/ViewExtractor as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
GeorgeElsham/ViewExtractor
Extract SwiftUI views from ViewBuilder content.
.package(url: "https://github.com/GeorgeElsham/ViewExtractor.git", from: "1.0")

ViewExtractor

Extract SwiftUI views from ViewBuilder content.

Example

Here is an example which creates a VStack with Divider()s in between.

View code

struct DividedVStack: View {
    private let views: [AnyView]
    
    init<Views>(@ViewBuilder content: ViewContent<Views>) {
        views = ViewExtractor.getViews(from: content)
    }
    
    var body: some View {
        VStack(spacing: 0) {
            ForEach(views.indices) { index in
                if index != 0 {
                    Divider()
                }
                
                views[index]
            }
        }
    }
}

Usage

DividedVStack {
    Text("View 1")
    Text("View 2")
    Text("View 3")
    Image(systemName: "circle")
}

Result

GitHub

link
Stars: 1
Last commit: 1 week ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Release Notes

Initial release
1 week ago

First release of ViewExtractor.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API