Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
You can insert some Blocks before and after the method like Aspect Oriented Programming.
Objective-C C++ Ruby
Pull request Compare This branch is 36 commits behind master.

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
BlockInjection.xcworkspace
BlockInjection
BlockInjectionTest
.gitignore
BlockInjection.podspec
LICENSE
Readme.md

Readme.md

BlockInjection

BlockInjection is a helpful library for iOS and Mac OS X.

You can insert some Blocks before and after the method by this library.

Samples

For example, if you use Google Analytics, you can embed the code for tracking without polluting your original source code.

#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 use NSString instead of Selector and Class.

#import "BILib.h"

[BILib injectToClassWithName:@"ViewController" methodName:@"buttonDidPush:" preprocess:^{

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

}];

You can insert a Postprocess.

#import "BILib.h"

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

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

}];

You can use a instance method's argument in your block.

#import "BILib.h"

// Sample class

@interface Bizz : NSObject
- (void)sayMessage:(NSString*)message;
@end 

@implementation Bizz
- (void)sayMessage:(NSString*)message
{
  NSLog(@"Bizz says: %@", message);
}
@end 

// ...

[BILib injectToClass:[Bizz class] selector:@selector(sayMessage:) preprocess:^(Bizz* bizz, NSString* message){

  // This code is called just before buttnDidPush:
  [tracker sendEventWithCategory:@"Bizz"
                      withAction:@"sayMessage"
                       withLabel:message //< You can use the argument that is passed to sayMessage:
                       withValue:0];

}];

// ...
Something went wrong with that request. Please try again.