gpt4 book ai didi

swift - 在协议(protocol)方法上设置断点

转载 作者:可可西里 更新时间:2023-11-01 00:39:19 25 4
gpt4 key购买 nike

基本上,我需要在协议(protocol)方法上设置一个断点,以便捕获对符合该协议(protocol)的对象的所有调用。我有一个自定义框架,其中包含许多符合协议(protocol)的类,因此在每个类上手动设置断点是不可行的。

我尝试从 Xcode 编辑器设置断点:

enter image description here

,但是在设置断点时,我只得到分配方法的断点: allocation breakpoints

,正如预期的那样,调试器在调用 doSomething() 时不会停止。

我也尝试添加符号断点,这里也没有运气: enter image description here

下面是一些演示代码来说明这一点:

protocol TestProtocol {
func doSomething()
func doAnotherThing()
}

class TestConformingClass: TestProtocol {
func doSomething() {
print("Yay")
}

func doAnotherThing() {
print("Hooray")
}
}

有没有办法拦截对属于协议(protocol)要求列表一部分的方法的所有调用?

最佳答案

在 lldb 中运行以下命令应该可以解决问题:

breakpoint set --name doSomething
breakpoint set --name doAnotherThing

可能,甚至以下方法也可能起作用:

breakpoint set --name doSomething --name doAnotherThing

关于swift - 在协议(protocol)方法上设置断点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49034902/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com