Notification about object method invocation

Is there a way in objective-c to find out if a method of an object has been invoked, by lets say something similar to KVO?

I have tracking code that always needs to go inside viewDidAppear and viewDidDissapear. I would like to be notified when any of those methods has been called so I can either start tracking or stop tracking an object out side of those two methods.

You could probably say why would I need it if I could just call my tracking code inside those two methods... Well I want to take this hassel from the users and automate the tracking process.


This is what is currently going on:

- (void)viewDidAppear:(BOOL)animated{
    [self.view trackWithKey:@"Unique UI Element key"];

- (void)viewDidDisappear:(BOOL)animated{
    [self.view stopTracking];

This is what I would like to do:


The tracker object would listen on its parents ViewDidAppear and viewDidDisappear method invocations, so when they are fired it would either call start or stop tracking.


Google for "Method Swizzling". Understand it completely. That should help you solve your problem.

Need Your Help

PHP How to compare date and date?

php date comparison

I have this value from database:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.