简体   繁体   English

是否可以在Objective-C中的现有类上记录方法调用

[英]Is it possible to log a method call on an existing class in Objective-C

I am currently programming a kind of analytics kit for some of my apps. 我目前正在为我的某些应用程序编写一种分析工具包。 Now I want to log every view which was on screen (eg every viewDidAppear: call UIViewController class). 现在,我想记录屏幕上的每个视图(例如,每个viewDidAppear:调用UIViewController类)。 The most important thing is, that I do not want to change the code of my existing classes. 最重要的是,我不想更改现有类的代码。 So my question is, if there is a possibility to log each UIViewController which appeared on screen. 所以我的问题是,是否有可能记录出现在屏幕上的每个UIViewController。

Thanks in advance. 提前致谢。

Without having to change your existing code, you could use a category and method swizzling to do exactly what you want. 无需更改现有代码,您就可以使用类别和方法来完成您想要的事情。

See here for more info: http://www.cocoadev.com/index.pl?MethodSwizzling 有关更多信息,请参见此处: http : //www.cocoadev.com/index.pl?MethodSwizzling

You could create a BaseViewController and inherit all your view controllers from this base controller. 您可以创建BaseViewController并从该基本控制器继承所有视图控制器。 Inside the base controller's viewDidAppear, viewDidDisappear etc.. log what you want to. 在基本控制器的viewDidAppear,viewDidDisappear等内部。记录您想要的内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM