2010-11-12 17 views

उत्तर

41

मुझे नहीं पता कि वास्तव में DebugPrintControlHierarchy मुद्रित है, लेकिन एनएसवीव के पास एक उपयोगी विधि कॉल _subtreeDescription है जो रिसीवर के नीचे पूरे पदानुक्रम का वर्णन करने वाली स्ट्रिंग देता है, जिसमें वर्ग, फ्रेम और अन्य उपयोगी जानकारी शामिल है।

अग्रणी _ अंडरस्कोर के बारे में डरो मत। यह सार्वजनिक एपीआई नहीं है, लेकिन इसे जीडीबी में सार्वजनिक उपयोग के लिए स्वीकृत किया गया है। आप कुछ नमूना आउटपुट के साथ in the AppKit release notes का उल्लेख कर सकते हैं।

5

यहाँ एक NSView श्रेणी की हिम्मत मैं थोड़ी देर वापस बनाया है:

+ (NSString *)hierarchicalDescriptionOfView:(NSView *)view 
             level:(NSUInteger)level 
{ 

    // Ready the description string for this level 
    NSMutableString * builtHierarchicalString = [NSMutableString string]; 

    // Build the tab string for the current level's indentation 
    NSMutableString * tabString = [NSMutableString string]; 
    for (NSUInteger i = 0; i <= level; i++) 
    [tabString appendString:@"\t"]; 

    // Get the view's title string if it has one 
    NSString * titleString = ([view respondsToSelector:@selector(title)]) ? [NSString stringWithFormat:@"%@", [NSString stringWithFormat:@"\"%@\" ", [(NSButton *)view title]]] : @""; 

    // Append our own description at this level 
    [builtHierarchicalString appendFormat:@"\n%@<%@: %p> %@(%li subviews)", tabString, [view className], view, titleString, [[view subviews] count]]; 

    // Recurse for each subview ... 
    for (NSView * subview in [view subviews]) 
    [builtHierarchicalString appendString:[NSView hierarchicalDescriptionOfView:subview 
                      level:(level + 1)]]; 

    return builtHierarchicalString; 
} 

- (void)logHierarchy 
{ 
    NSLog(@"%@", [NSView hierarchicalDescriptionOfView:self 
               level:0]); 
} 

एक NSView श्रेणी में प्रयोग

इस डंप, उस में यह डंप। जहां भी आप इसका उपयोग करना चाहते हैं श्रेणी श्रेणी शीर्षलेख शामिल करें, फिर [myView logHierarchy]; पर कॉल करें और इसे देखें।

2

स्विफ्ट 4.

MacOS:

extension NSView { 

    // Prints results of internal Apple API method `_subtreeDescription` to console. 
    public func dump() { 
     Swift.print(perform(Selector(("_subtreeDescription")))) 
    } 
} 

आईओएस:

extension UIView { 

    // Prints results of internal Apple API method `recursiveDescription` to console. 
    public func dump() { 
     Swift.print(perform(Selector(("recursiveDescription")))) 
    } 
} 

(डीबगर में) उपयोग: po myView.dump()

संबंधित मुद्दे