Created
May 19, 2020 10:36
-
-
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.
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