Created
March 5, 2015 07:53
-
-
Save benrudhart/552306f7576af3c5e943 to your computer and use it in GitHub Desktop.
dumping of NSView & subviews
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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