【问题标题】:Swift 3 and lldb: Print frame of UIView, given hex addressSwift 3 和 lldb:UIView 的打印帧,给定十六进制地址
【发布时间】:2016-12-13 23:45:40
【问题描述】:

调试 iOS 目标、Swift 3、Xcode 8.2、lldb-360.1.68

我想打印一个 UIView 的frame,我在之前的断点处抓取了它的地址。这是我最好的镜头,但结果令人失望:

(lldb) expr -l objc -O -- NSStringFromRect((CGRect)([(UIView*)0x7a241b30 frame]))
error: use of undeclared identifier 'CGRect'

谢谢!

【问题讨论】:

    标签: ios swift uiview lldb


    【解决方案1】:

    如果您在 swift 调试器中,可以使用 unsafeBitCast 将指针转换为类型。

    po unsafeBitCast(0x7a241b30, to: UIView.self).frame
    

    【讨论】:

    • 谢谢@featherless,但这对我不起作用。我认为 swift debugger 你的意思是 lldb。以下是发生的情况:(lldb) po unsafeBitCast(0x7a241b30, to: UIView.self).frameerror: use of undeclared identifier 'to' 尽管根据当前的 Swift 3 文档,您对 unsafeBitCast() 的使用似乎是正确的,但我尝试了几种变体,但仍然在 to 上收到此错误错误。
    • 那太不幸了! lldb 是否以任何方式为您自动完成?您使用的 Swift 版本可能与我使用的不同。试试unsafeBitCast(0x7a241b30, UIView.self)
    • 我最近没有看到 lldb 自动完成功能。我刚刚使用全新的版本 8.2 (8C38) 重新测试。我正在使用 Swift 3。您之前的评论建议我删除 to:.frame。这导致error: property 'self' not found on object of type 'UIView',这当然更荒谬。删除.self 也会导致error: unexpected interface name 'UIView': expected expression。啊,我想我现在看到了模式。没有用 :)) 这对你有用吗?如果是,你使用的是什么 Xcode 和 Swift 版本?
    • 听起来你真的很不幸 :) 我在 Xcode 版本 8.1 (8B62
    • 好吧,我们很快就会使用 Xcode 8.2。 @featherless,所以当我在 Apple 的 Bug Reporter 中提交错误时,我可以描述任何回归,请测试我的命令和你的命令在 Xcode 8.1 中是否正常工作。我的:expr -l objc -O -- NSStringFromRect((CGRect)([(UIView*)0xXXXXXXXX frame])) 你的:po unsafeBitCast(0xXXXXXXXX, to: UIView.self).frame。谢谢。
    【解决方案2】:

    我找到了一个答案——更准确地说,一个work-less-around您不需要打印framebounds,因为它们的值包含在description中。在这种情况下,只需输入

    (lldb) po (UIView*)0x7a241b30
    

    framebounds 的值将存在于您将获得的数百行标准输出中。

    我仍然希望能解释一下为什么CGRect 是一个未声明的标识符,等等。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-07-04
      • 1970-01-01
      • 1970-01-01
      • 2017-07-22
      • 1970-01-01
      • 2015-02-14
      • 1970-01-01
      相关资源
      最近更新 更多