Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save sarunw/70ed2818e97ab87118379559f6270912 to your computer and use it in GitHub Desktop.
Save sarunw/70ed2818e97ab87118379559f6270912 to your computer and use it in GitHub Desktop.
An experimental way to extract SwiftUI views from an TupleView built by ViewBuilder.
import SwiftUI
func extractViewsFromContent<Content: View> (@ViewBuilder content: () -> Content) -> [Any] {
let tupleView = content()
let tupleViewMirror = Mirror(reflecting: tupleView)
let tuple = tupleViewMirror.children.first!.value
let tupleMirror = Mirror(reflecting: tuple)
let views = tupleMirror.children.map { $0.value }
return views
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment