Skip to content

Instantly share code, notes, and snippets.

@stleamist
Created May 19, 2020 10:36
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save stleamist/c5867492df54d31c14bb2684ea38bc36 to your computer and use it in GitHub Desktop.
Save stleamist/c5867492df54d31c14bb2684ea38bc36 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