Created
January 25, 2024 09:18
-
-
Save shaps80/6e17641f706d982e35a42b728e16ee99 to your computer and use it in GitHub Desktop.
Recursively prints the entire SwiftUI View tree using Mirror
This file contains hidden or 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 | |
| extension Mirror { | |
| func printRecusively() { | |
| for child in children { | |
| let label = child.label ?? "<unknown>" | |
| let value = child.value | |
| print(type(of: value), label, value, separator: " | ") | |
| Mirror(reflecting: value) | |
| .printRecusively() | |
| } | |
| } | |
| } | |
| extension View { | |
| func debug() -> some View { | |
| print(body) | |
| Mirror(reflecting: self).printRecusively() | |
| return self | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment