在协议方法上设置断点

时间:2018-02-28 17:02:47

标签: swift xcode debugging breakpoints lldb

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

我尝试从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")
    }
}

有没有办法拦截对作为协议要求列表一部分的方法的所有调用?

1 个答案:

答案 0 :(得分:4)

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

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

可能,即使以下情况也可行:

breakpoint set --name doSomething --name doAnotherThing
相关问题