Swift 中的递归描述方法? [英] recursiveDescription method in Swift?
本文介绍了Swift 中的递归描述方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法在 Swift 中使用 [self.view recursiveDescription]?我正在尝试使用此方法,但出现以下错误:
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 have a member named 'recursiveDescription'
有什么建议吗?
推荐答案
为了访问私有/未记录的 Objective-C API(如 UIView
上的 -recursiveDescription
方法) 从 Swift 您可以执行以下操作:
In order to access private / undocumented Objective-C API (like the -recursiveDescription
method on UIView
) from Swift you can do the following:
- 在定义私有方法的类上创建一个新的 Objective-C 类别(例如
UIView
). - 如果 Xcode 询问您有关配置桥接头的问题,请点击 Yes.(如果您的项目中已有桥接头,则将跳过此步骤).
- 可以删除类别的实现文件 (.m).
在类别头中声明私有方法:
- 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
现在可以设置断点并打印出LLDB中的递归描述:
Now you can set a breakpoint and print out the recursive description in LLDB:
po view.recursiveDescription() as NSString
这篇关于Swift 中的递归描述方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文