Swift中的recursiveDescription方法? [英] recursiveDescription method in Swift?

查看:215
本文介绍了Swift中的recursiveDescription方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在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 方法)您可以执行以下操作:

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


  1. 在类中创建一个新的Objective-C类别,定义私有方法(例如 UIView )。

  2. 如果Xcode要求您配置桥接标头,请按。 (如果项目中已经有一个桥接标题,则会跳过此步骤。)

  3. 可以删除该类别的实现文件(.m)。

  4. 在类别标题中声明私有方法:

  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


现在你可以设置一个断点并在LLDB中打印出递归描述:

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

po view.recursiveDescription() as NSString

这篇关于Swift中的recursiveDescription方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆