在运行时添加标志(Xcode工具)

时间:2023-01-27 13:41:31

I am using Instruments to debug my allocation in my iOS app and was wondering if there was a way to add flags to the trace while the code is running. For example, I'd like a flag that says "user tapped on button X" to be added automatically once the user tapped on that button.

我正在使用工具调试iOS应用程序中的分配,我想知道是否有一种方法可以在代码运行时向跟踪添加标记。例如,我想要一个标志,上面写着“用户点击按钮X”,一旦用户点击那个按钮,就会自动添加。

From what it seems from Apple docs, you can only add those flags 'after the fact'.

从苹果文档来看,你只能在“事后”添加这些标志。

1 个解决方案

#1


0  

You could try the approach recommended here:

你可以试试这里推荐的方法:

http://ioscodesnippet.com/post/43288248813/method-swizzling-in-objective-c

http://ioscodesnippet.com/post/43288248813/method-swizzling-in-objective-c

Basically, you can add a trace onto a particular method that you know you want to trace in advance by swizzling out the real implementation for your custom implementation which logs a tracing statement before calling the real implementation (in this case, you can override -[UIButton endTrackingWithTouch: withEvent:]).

基本上,您可以在特定的方法上添加一个跟踪,您知道您想要预先跟踪,在调用真正的实现之前(在本例中,您可以重写-[UIButton endTrackingWithTouch: withEvent:]),在您的自定义实现中进行真正的实现。

#1


0  

You could try the approach recommended here:

你可以试试这里推荐的方法:

http://ioscodesnippet.com/post/43288248813/method-swizzling-in-objective-c

http://ioscodesnippet.com/post/43288248813/method-swizzling-in-objective-c

Basically, you can add a trace onto a particular method that you know you want to trace in advance by swizzling out the real implementation for your custom implementation which logs a tracing statement before calling the real implementation (in this case, you can override -[UIButton endTrackingWithTouch: withEvent:]).

基本上,您可以在特定的方法上添加一个跟踪,您知道您想要预先跟踪,在调用真正的实现之前(在本例中,您可以重写-[UIButton endTrackingWithTouch: withEvent:]),在您的自定义实现中进行真正的实现。