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:
[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.
- Open Source: Objective-C Library That Dynamically Enables Block Based Calls – Like Magic!
- Open Source: Massive Collection Of Objective-C Blocks Extensions
- Tutorial: How To Work Some Objective-C Magic To Add Blocks Support Into UIMenuItem
- Easy To Use Objective-C Modeling Framework With JSON Encoding, Minimal Boilerplate Code
- Open Source: Macros And Additions For Making Objective-C Coding More Concise
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.