Get Updates By E-mail 

Article Written By:
Johann Dowa

Open Source Objective-C Library Allowing You To Inject A Block Of Code Before/After Methods

  •  
  •  
  •  
  •  
  •  

I’ve mentioned some great open source project projects for working with Objective-C blocks such as the BlocksKit project that provides a massive number of extensions for Cocoa Touch libraries enabling a blocks based syntax.

Here’s a very nifty open source library called BlockInjection from Tokorom.

What block injection allows you to do is inject an objective-c block that will execute before or after a specified method.

You simply supply BlockInjection with the class and method, and the block of code and it will do the rest.

Here’s an example from the readme showing how you would inject a code block to run before a hypothetical buttonDidPush would execute in a ViewController class:

#import "BILib.h"

[BILib injectToClass:[ViewController class] selector:@selector(buttonDidPush:) preprocess:^{

  // This code is called just before buttnDidPush:
  [tracker sendEventWithCategory:@"uiAction"
                      withAction:@"buttonDidPush"
                       withLabel:nil
                       withValue:0];

}];

You can find BlockInjection on Github here.

A very interesting library for working with blocks.


  •  
  •  
  •  
  •  
  •  

Submit A Resource

Have you created a useful tutorial, library or tool for iOS development that you would like to get in front of our 300,000+ monthly page views from iOS developers?

You can submit the url here.

The resources we feel will appeal to our readers the most will be posted on the front page.

Comments