Skip to content

Instantly share code, notes, and snippets.

@cschep
Last active May 15, 2017 18:13
Show Gist options
  • Select an option

  • Save cschep/ceb1fc46e2e3571a208eb8c770ab2e5a to your computer and use it in GitHub Desktop.

Select an option

Save cschep/ceb1fc46e2e3571a208eb8c770ab2e5a to your computer and use it in GitHub Desktop.
func logViewHierarchy(view: UIView) -> String {
var viewsPrinted = Set<UIView>()
var result: String = ""
func printViews(_ view: UIView, level: Int) {
guard !viewsPrinted.contains(view) else { return }
let padString = String(repeating: " | ", count: level)
result += ("\(padString) \(type(of: view))\n")
viewsPrinted.insert(view)
for subview in view.subviews {
printViews(subview, level: level + 1)
}
}
printViews(view, level: 0)
return result
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment