title: Can I swizzle didSelectRowAtIndexPath: of UITableViewDelegate?
body: <p>The problem is this: </p>
  
  <p>I need to be able to get analytics on didSelectRowAtIndexPath throughout a big existing app with lots of tableViews. </p>
  
  <p>My first thought of this is doing method swizzling on didSelectRowAtIndexPath: but my app crashes with "unrecognized selector sent to instance" message depending on the stuff is accessed in the original didSelectRowAtIndexPath implementation.</p>
  
  <p>Here is how I try to achieve this in a UIViewController category:</p>
  
  <pre><code>#import "UIViewController+Swizzle.h"
  
  @implementation UIViewController (Swizzle)
  
  - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPathSwizzled:(NSIndexPath *)indexPath {
      NSLog(@"Log something here");
      [self tableView:tableView didSelectRowAtIndexPathSwizzled:indexPath];
  }
  
  + (void) initialize {
      BOOL conformsToTableViewDelegate = class_conformsToProtocol(self, @protocol(UITableViewDelegate));
      if(conformsToTableViewDelegate) {
          Method method1 = class_getInstanceMethod(self, @selector(tableView:didSelectRowAtIndexPath:));
          Method method2 = class_getInstanceMethod(self, @selector(tableView:didSelectRowAtIndexPathSwizzled:));
          method_exchangeImplementations(method1, method2);
      }
  }
  
  
  @end
  </code></pre>
  
  <p>Can this be accomplished? If so, what am I doing wrong?</p>
  
  <p>Thanks!</p>