Skip to content

Instantly share code, notes, and snippets.

@benrudhart
Created March 5, 2015 07:53
Show Gist options
  • Save benrudhart/552306f7576af3c5e943 to your computer and use it in GitHub Desktop.
Save benrudhart/552306f7576af3c5e943 to your computer and use it in GitHub Desktop.
dumping of NSView & subviews
// Dumping.swift
//
// Copyright (c) 2015 Ben Rudhart | www.app-grade.de
// This class is ported from an objectiv-c version found here: http://www.blackdogfoundry.com/blog/common-xcode4-plugin-techniques/
import Foundation
import AppKit
extension NSView {
func dumpWithIndent(indent: String) {
let clazz = String.fromCString(object_getClassName(self))!
var info = ""
if self.respondsToSelector("title") {
if let title = self.valueForKey("title") as! String? where count(title) > 0 {
info += " title=\(title)"
}
}
if self.respondsToSelector("stringValue") {
if let string = self.valueForKey("stringValue") as! String? where count(string) > 0{
info += " stringValue=\(string)"
}
}
if let tooltip = self.toolTip where count(toolTip!) > 0 {
info += " tooltip=\(tooltip)"
}
println("\(indent) \(clazz) \(info)")
if self.subviews.count > 0 {
let subIndent = indent + ((count(indent)/2) % 2 == 0 ? "| " : ": ")
for subview in self.subviews {
subview.dumpWithIndent(subIndent)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment