Forked from stleamist/extractViewsFromContent.swift
Created
December 30, 2020 08:37
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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