Skip to content

Instantly share code, notes, and snippets.

@Coderian
Created October 14, 2016 02:58
Show Gist options
  • Save Coderian/424c83dbe6eeb1752c63686356353e1b to your computer and use it in GitHub Desktop.
Save Coderian/424c83dbe6eeb1752c63686356353e1b to your computer and use it in GitHub Desktop.
iOS UIViewの階層構造をprintする extension by Swift 3.0 ref: http://qiita.com/gi0_0iv/items/159fcdb19074ee66ca38
<UILayoutContainerView: ...
<UINavigationTransitionVIew: ...
:
import Funcation
import UIKit
extension UIWindow {
func printSubviewHierarchy() {
var tabs:String = ""
printSubviews(subviews: self.subviews, tabs: &tabs)
}
private func printSubviews(subviews: [UIView], tabs:inout String) {
tabs += " "
for view in subviews {
print(tabs + "\(view.self)")
printSubviews(subviews: view.subviews, tabs: &tabs)
}
tabs.remove(at: tabs.index(before: tabs.endIndex))
}
}
@IBAction func tapped(_ sender: UIButton){
self.view.window?.printSubviewHierarchy()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment