Skip to content

Instantly share code, notes, and snippets.

@shaps80
Created January 25, 2024 09:18
Show Gist options
  • Select an option

  • Save shaps80/6e17641f706d982e35a42b728e16ee99 to your computer and use it in GitHub Desktop.

Select an option

Save shaps80/6e17641f706d982e35a42b728e16ee99 to your computer and use it in GitHub Desktop.
Recursively prints the entire SwiftUI View tree using Mirror
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