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.

DeliciousTwitterFacebookRedditLinkedInEmail

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

©2013 iOS App Dev Libraries, Controls, Tutorials, Examples and Tools. All Rights Reserved.

Leave a Reply

Your email address will not be published. Required fields are marked *