简体   繁体   中英

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). 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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