recursiveDescription method in Swift?

前端 未结 8 902
天命终不由人
天命终不由人 2020-12-23 09:50

Is there a way to use [self.view recursiveDescription] in Swift? I am trying to use this method but I am getting the following error:

\'UIView\' does not hav         


        
相关标签:
8条回答
  • 2020-12-23 10:37

    Add to the bridging header a declaration of a category of UIView with that method.

    0 讨论(0)
  • 2020-12-23 10:38

    If you want to display the view hierarchy in lldb, you do not have to add any categories or bridging headers or anything like that. When debugging Objective-C code, one would generally use the following command at the (lldb) prompt:

    po [[UIWindow keyWindow] recursiveDescription]
    

    If, though, you've paused in a Swift frame, lldb may expect a Swift expression. You can, though, explicitly tell expr (the po abbreviation is actually calling expression) which language the expression is in:

    expr -l objc++ -O -- [[UIWindow keyWindow] recursiveDescription]
    

    The same patterns occur in iOS 8, when viewing the view controller hierarchy, using:

    po [UIViewController _printHierarchy]
    

    or, in Swift frame:

    expr -l objc++ -O -- [UIViewController _printHierarchy]
    

    In WWDC 2018 Advanced Debugging with Xcode, they suggest getting yourself away from this complicated expr syntax by defining an alias, poc, by creating a text file, ~/.lldbinit with the following line:

    command alias poc expression -l objc -O --
    

    Then you can do things like:

    poc [UIViewController _printHierarchy]
    

    It's worth noting that Xcode 8 introduced the view debugger (click on ), offering a more interactive way to analyze the view hierarchy, largely eliminating the need for the LLDB recursiveDescription of the view hierarchy. For more information see WWDC 2016 video Visual Debugging with Xcode. Admittedly, sometimes we end up having to fall back to the recursiveDescription technique shown above, but most of the time the view debugger makes this a far more natural, intuitive process.

    And in Xcode 9, they've expanded this view debugger so it now includes the relevant view controllers, too:

    0 讨论(0)
提交回复
热议问题