In order to access private / undocumented Objective-C API (like the -recursiveDescription
method on UIView
) from Swift you can do the following:
- Create a new Objective-C category on the class the private method is defined in (e.g.
UIView
).
- 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).
- The implementation file (.m) of the category can be removed.
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
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…