开发者

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

开发者 https://www.devze.com 2023-03-13 06:16 出处:网络
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 (e.g. every viewDidAppear: call UIViewController class).

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 (e.g. every viewDidAppear: call UIViewController class). 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.

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


You could create a BaseViewController and inherit all your view controllers from this base controller. Inside the base controller's viewDidAppear, viewDidDisappear etc.. log what you want to.

0

精彩评论

暂无评论...
验证码 换一张
取 消