Xcode调试器在视图上调用方法 [英] call method on view from Xcode debugger
问题描述
假设我从Xcode调试器的调试视图层次结构中选择一个UIView。我可以打印其描述;看起来像这样:
$ 17的打印说明:
< MyView:0x7fc6a451c030;框架=(0 0; 375270);层=< CALayer:0x608000029700>
那很好,但是我真正想做的是调用[myView myMethod]并打印结果。在这种特殊情况下,myMethod返回一个NSString,但是我想那并不总是正确的。
我读过从Xcode Debugger调用方法?,但这似乎对我的情况没有帮助,因为myView不是我自己。
-
您可以在LLDB(控制台)中将语言设置为Swift
(lldb)设置为target.language swift
-
在
MyView
所属的类中并在确定已被实例化的作用域中添加一个Breakpoint。 -
启动应用程序,并在达到断点时:
-
type
po
(打印对象),后跟您的视图名称(lldb)po $ myView
如果您想要更多详细信息,请使用 p
(简短对于 print ):(lldb)p myView
-
在视图前调用
e
或expr
(的缩写)表达式
):(lldb)expr $ myView.myMethod()
-
要查看UI中的更改,请致电
(lldb)expr CATransaction.flush()
有关更多信息,此处是lldb命令的参考
您还可以使用打印UI元素描述后给出的内存地址,并将其转换为可用类型:
(lldb)expr-导入UIKit
(lldb)expr-让$ myView = unsafeBitCast (0x7fc6a451c030,至:MyView.self)
(lldb)expr $ myView.myMethod()
//或者如果要创建一个具有该结果的变量:
(lldb) expr $ string = $ myView。 myMethod()
(lldb)po $ string
Suppose I select a UIView from the "debug view hierarchy" in the Xcode debugger. I can print its description; it looks something like this:
Printing description of $17:
<MyView: 0x7fc6a451c030; frame = (0 0; 375 270); layer = <CALayer: 0x608000029700>>
That's nice, but what I really want to do is call [myView myMethod] and print the result. In this particular case, myMethod returns an NSString, but I imagine that won't always be true.
I've read Calling methods from Xcode Debugger?, but it does not appear to help for my case, because myView is not self.
You can set the language to Swift in LLDB (the console)
(lldb) settings set target.language swift
Add a breakPoint in the class where
MyView
belongs, and in a scope where you're sure that is it is already instantiated.Launch the app, and when the breakpoint is reached:
type
po
(print object) followed by the name of your view(lldb) po $myView
if you want more details use p
(short for print): (lldb) p myView
Call your method on the view preceded by
e
orexpr
(short forexpression
) :(lldb) expr $myView.myMethod()
To see changes in the UI call this
(lldb) expr CATransaction.flush()
For more, here is the reference for lldb commands.
You could also use the memory address, given after printing the description of your UI element, and cast that to a usable type:
(lldb) expr -- import UIKit
(lldb) expr -- let $myView = unsafeBitCast(0x7fc6a451c030, to: MyView.self)
(lldb) expr $myView.myMethod()
//Or if you'd like to create a variable with that result:
(lldb) expr let $string = $myView.myMethod()
(lldb) po $string
这篇关于Xcode调试器在视图上调用方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!