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.

Revisions

  1. cschep revised this gist May 15, 2017. 1 changed file with 15 additions and 1 deletion.
    16 changes: 15 additions & 1 deletion gistfile1.swift
    Original file line number Diff line number Diff line change
    @@ -17,4 +17,18 @@ func logViewHierarchy(view: UIView) -> String {
    printViews(view, level: 0)

    return result
    }
    }

    let v = UIView()
    for i in 0...10 {
    let view = UIView()

    if i % 2 == 0 {
    view.addSubview(UIView())
    }

    v.addSubview(view)
    }

    let result = logViewHierarchy(view: v)
    print(result)
  2. cschep revised this gist May 15, 2017. 1 changed file with 1 addition and 2 deletions.
    3 changes: 1 addition & 2 deletions gistfile1.swift
    Original file line number Diff line number Diff line change
    @@ -6,8 +6,7 @@ func logViewHierarchy(view: UIView) -> String {
    guard !viewsPrinted.contains(view) else { return }

    let padString = String(repeating: " | ", count: level)
    result += ("\(padString) \(type(of: view))")
    result += "\n"
    result += ("\(padString) \(type(of: view))\n")
    viewsPrinted.insert(view)

    for subview in view.subviews {
  3. cschep renamed this gist May 15, 2017. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  4. cschep created this gist May 15, 2017.
    21 changes: 21 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    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))")
    result += "\n"
    viewsPrinted.insert(view)

    for subview in view.subviews {
    printViews(subview, level: level + 1)
    }
    }

    printViews(view, level: 0)

    return result
    }