Skip to content

Instantly share code, notes, and snippets.

@Geri-Borbas
Created July 26, 2020 00:45
Show Gist options
  • Select an option

  • Save Geri-Borbas/e915482b16020f4509671c44600036ea to your computer and use it in GitHub Desktop.

Select an option

Save Geri-Borbas/e915482b16020f4509671c44600036ea to your computer and use it in GitHub Desktop.
Print recursive `UIKit` view hierarchy information.
extension UIView {
func printViewHierarchyInformation(_ level: Int = 0) {
printViewInformation(level)
self.subviews.forEach { $0.printViewHierarchyInformation(level + 1) }
}
func printViewInformation(_ level: Int) {
let leadingWhitespace = String(repeating: " ", count: level)
let className = "\(Self.self)"
let superclassName = "\(self.superclass!)"
print("\(leadingWhitespace)\(className): \(superclassName)")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment