recursiveDescription method in Swift?

前端 未结 8 940
天命终不由人
天命终不由人 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:31

    In order to access private / undocumented Objective-C API (like the -recursiveDescription method on UIView) from Swift you can do the following:

    1. Create a new Objective-C category on the class the private method is defined in (e.g. UIView).
    2. Hit Yes if Xcode asks you about configuring an bridging header. (If you have already an bridging header in your project this step will be skipped).
    3. The implementation file (.m) of the category can be removed.
    4. Declare the private method in the category header:

      // UIView+Debugging.h
      
      @interface UIView (Debugging)
      - (id)recursiveDescription;
      @end
      

    Now you can set a breakpoint and print out the recursive description in LLDB:

    po view.recursiveDescription() as NSString
    

提交回复
热议问题